Hi guys! I have a 2-part problem that I'm trying to solve with a PivotTable loop:
Firstly, I've created a loop on my PivotField "GCI" that moves through each PivotItem in my PivotTable until it has moved through all the items (this should be working fine in code below).
Secondly, each time the code moves to a new PivotItem in the list, I need to copy the range O4:T4 (it's on the same sheet as the pivot table and will never change) and paste those VALUES into a different range of cells (lets say V4:AA4). The Kicker.. Each time I copy range O4:T4 for a PivotItem, I need to paste the VALUES below the previously pasted VALUES. So if we hypothetically just pasted PivotItem1's range into V4:AA4, we need to paste PivotItem2's range into V5:AA5 (right below it). This process should repeat until the loop has moved through all the PivotItems. When completed, I will have a table in V:AA that has all of these pasted VALUES from each PivotItem. Whew, hopefully I explained that clearly enough!! Any help is really appreciated on this and I am open to any modifications to the original loop code. I'm not sure if I need to use an OFFSET function on this or how to approach it
!
Dim i As Integer
Dim sItem As String
Application.ScreenUpdating = False
With ActiveSheet.PivotTables("PivotTable1")
.PivotCache.MissingItemsLimit = xlMissingItemsNone
.PivotCache.Refresh
With .PivotFields("GCI")
'---hide all items except item 1
.PivotItems(1).Visible = True
For i = 2 To .PivotItems.Count
.PivotItems(i).Visible = False
Next
For i = 1 To .PivotItems.Count
.PivotItems(i).Visible = True
If i <> 1 Then .PivotItems(i - 1).Visible = False
sItem = .PivotItems(i)
'---copy range O4:T4 and paste VALUES in V4
'---the second copied O4:T4 range would move to V5 and so on
'---need to repeat this for every PivotItem in list
Next i
End With
End With
Bookmarks