I have a report that I run daily and then create Pivot Tables off of it. I know how to create the code to completely un-filter the entire pivot table in order to refresh it without errors. However subsequent to that I am trying to then re-filter it - select specific pivot items from that pivot table. The issue I am running into is that at times the specific items that I want to select are not there; though the next day they could be.
In other words I have 10 possible items I want to have show up amongst 50 others. However any one of those 10 might be missing on any given day (since there was nothing associated with that lable that day).
I know how to select items individually however how do I get past the error when the code can't find the item?
This is the code I am using.
Sub AddFilter()
With ActiveSheet.PivotTables(1).PivotFields("Status")
.PivotItems("RECC").Visible = False
.PivotItems("WETC").Visible = False
.PivotItems("(Blank)").Visible = False
End With
End Sub
If, for example, that day "RECC" is not there I get the error
"Unable to get the PivotItems property of the PivotField class"
I tried several ways to "on error go to next" and they all failed.
In other words I have 10 possible items I want to have show up amongst 50 others. However any one of those 10 might be missing on any given day (since there was nothing associated with that lable that day).
I know how to select items individually however how do I get past the error when the code can't find the item?
This is the code I am using.
Sub AddFilter()
With ActiveSheet.PivotTables(1).PivotFields("Status")
.PivotItems("RECC").Visible = False
.PivotItems("WETC").Visible = False
.PivotItems("(Blank)").Visible = False
End With
End Sub
If, for example, that day "RECC" is not there I get the error
"Unable to get the PivotItems property of the PivotField class"
I tried several ways to "on error go to next" and they all failed.