I am trying to remove some fields from a Pivot Table. The Table changes but the list of items I am trying to remove stay the same.
It works if I just use the deselect code like this:
Set pf =ActiveSheet.PivotTables("PivotTable1").PivotFields("ServiceName")
pf.PivotItems("Disk").Visible = False
pf.PivotItems("SNMP").Visible = False
pf.PivotItems("POP").Visible = False..... and so on for about 140 Items
My problem comes when I have a Pivot table that does not contain the PivotItem. Run time error: "Unable to get the PivotItems property of the PivotField class
So I thought I would us a simple IF THEN:
If pf = ("POP") Then pf.PivotItems("POP").Visible = False
But it doesn't work. It doesn't do anything, no errors, no changes to the field. It just blinks and its done.
What am I missing?