Hi,
I am trying to loop through each pivot item in the pivot table filter called 'COMPANY_NAME'
This is the code I have so far but get an error on line 'PvItemL.Visible = False'
Sub PivotLoop()
Dim PvTable As PivotTable
Dim PvField As PivotField
Dim PvItem As PivotItem
Dim PvItemL As PivotItem
Set PvTable = ActiveSheet.PivotTables("PivotTable2")
Set PvField = PvTable.PivotFields("COMPANY_NAME")
Sheets("RAG GR & WF II").Select
For Each PvItem In PvField.PivotItems
For Each PvItemL In PvField.PivotItems
If PvItemL = PvItem Then
PvItemL.Visible = True
Else
PvItemL.Visible = False 'Error occurs here
End If
If Worksheets("RAG GR & WF II").Range("C20") > 20 Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
"C:\Users\anneg\Desktop\Daily Snapshot PDF\testing.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next
Next
End Sub
Can someone please give me a clue as to why this error comes up please?
Thanks
Bookmarks