|
Question : How Do I Test If A PivotItem Exists?
|
|
I'm using 'Removed' as a flag in a sheet I make a pivot table off of. This code hides the 'Removed' records in the table but will return an error if there are no records with the 'Removed' Flag.
With ActiveSheet.PivotTables("TradeBreaks").PivotFields("BreakStatus") .PivotItems("Removed").Visible = False End With
How can I test to see if the PivotItem exists?
|
|
Answer : How Do I Test If A PivotItem Exists?
|
|
Hi stopher2475, The reason you get an error with this when Removed is not there is that you try accessing a property of a non existing object (Nothing)
change > With ActiveSheet.PivotTables("TradeBreaks").PivotFields("BreakStatus") > .PivotItems("Removed").Visible = False > End With
to > With ActiveSheet.PivotTables("TradeBreaks").PivotFields("BreakStatus") if not(.PivotItems("Removed") is nothing) then > .PivotItems("Removed").Visible = False end if > End With
this way if the remove item is not there the manipulation on it would not occur and you will get no error. SnowFlake
|
|
|