Hi All,
I have a nice macro that I use to loop through pivot items and carry out a task for each item in the pivot table (code below). It works well, and right now it loops through all items in the pivot table.
I would like to add an if statement that if True skips the code and goes to the next pivot item. I’ve highlighted my attempt at this below, but it looks like I can’t nest For/Next statements, which is key functionality in the pivot filter loop.
Is there another way that I can accomplish this?
As always thanks so much for your help.
I have a nice macro that I use to loop through pivot items and carry out a task for each item in the pivot table (code below). It works well, and right now it loops through all items in the pivot table.
I would like to add an if statement that if True skips the code and goes to the next pivot item. I’ve highlighted my attempt at this below, but it looks like I can’t nest For/Next statements, which is key functionality in the pivot filter loop.
Is there another way that I can accomplish this?
As always thanks so much for your help.
Rich (BB code):
Dim ExternalLinks As Variant
Dim x As Long
Dim pt As PivotTable
Dim pi As PivotItem
Dim pf As PivotField
Dim ILoop As Long
Dim shape As Excel.shape
Application.ScreenUpdating = False
Set pt = Sheets("sheetnameiswhat").PivotTables(1)
Set pf = pt.PageFields(1)
'cycles through pivot table filter and carries out the below
For Each pi In pf.PivotItems
pf.CurrentPage = pi.Value
'if cell(i51) is zero, skip macro and go directly to next pi
If Range("i51") = 0 Then Next pi
End If
‘’ FUN CODE HERE''
Next pi