Guys,
I'm looking to loop through a pivot table filter and perform some actions on each item.
This code, appreciatively copied from the Internet, works great in a regular pivot table, but does nothing when the PivotTable is based on a data model.
Poking in, I've found:
-It finds the pivot table
-It finds the pagefield ( .count = 1)
-It finds no pivotitems
What am I missing?
Thanks,
Mike
I'm looking to loop through a pivot table filter and perform some actions on each item.
This code, appreciatively copied from the Internet, works great in a regular pivot table, but does nothing when the PivotTable is based on a data model.
Code:
Sub Loop_PivotItems()
'Turn off screen updating
Application.ScreenUpdating = False
'Store the sheet with the Pivot Table
Piv_Sht = ActiveSheet.Name
'Loop through every PivotItem in the PageField (Filter) of the Pivot Table
For Each PivotItem In ActiveSheet.PivotTables(1).PageFields(1).PivotItems
'Select the PivotItem
ActiveSheet.PivotTables(1).PageFields(1).CurrentPage = PivotItem.Value
'Do whatever you need here....
MsgBox (PivotItem.Value)
'Return to sheet with the Pivot Table
Sheets(Piv_Sht).Select
Next
'Turn on screen updating
Application.ScreenUpdating = True
End Sub
Poking in, I've found:
-It finds the pivot table
-It finds the pagefield ( .count = 1)
-It finds no pivotitems
What am I missing?
Thanks,
Mike