Consulting

Results 1 to 4 of 4

Thread: VBA Script for changing grouped data names in multiple pivot tables

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Post VBA Script for changing grouped data names in multiple pivot tables

    I have multiple pivot tables on multiple tabs all with the same data source. I have manually grouped some of the row items together, but all other pivot tables say "Group1", "Group2", etc. I changed the name in one of the pivots, but the others don't change. I'd like to set up a macro/vba script to change all other pivot tables' grouped names when I change the name on the first pivot. Does anyone have some script I can use? I tried this:

    Sub GroupText()
    Dim n As Integer
    Dim i As Integer
    Dim a As Variant
    
    Application.ScreenUpdating = False
    
    With Sheets("Sheet1")
        With .PivotTables("PivotTable1")
            With .PivotFields("ID")
                i = .PivotItems.Count
                ReDim a(i, 1)
                For n = 1 To i
                    a(n, 1) = .PivotItems(n).Caption
                Next n
            End With
        End With
    
        With .PivotTables("PivotTable2").PivotFields("ID")
            For n = 1 To i
                .PivotItems(n).Caption = a(n, 1)
            Next n
        End With
    End With
    End Sub
    But it kept getting hung up with : .PivotItems(n).Caption = a(n, 1)
    Last edited by SamT; 11-07-2015 at 06:52 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •