I have the code below, which I've been using for over a year to determine the items to show on my pivot table. The code is repeated 12 different times for 12 different Expense Detail files every morning. This morning, the code started displaying the "Unable" message at the line "PI.Visible = True" on one specific Expense Detail report. I can't see anything different with this expense detail report; it DOES have a "PROJECTED" column, and if I stop the code at the error and refresh the table it all appears just as it should, with "PROJECTED" hidden. Here's my tried and true code:
'Change this to determine what options you want to show/hide
With PT.PivotFields("MOS2")
For Each PI In PT.PivotFields("MOS2").PivotItems
If PI = "PROJECTED" Then
PI.Visible = False
Else
PI.Visible = True
End If
Next
End With
I tried a change to see if this would work better. Same problem.
'Change this to determine what options you want to show/hide
With PT.PivotFields("MOS2")
For Each PI In PT.PivotFields("MOS2").PivotItems
If PI <> "PROJECTED" Then
PI.Visible = True
Else
PI.Visible = False
End If
Next
End With
Any help with troubleshooting this one is greatly appreciated.
Bookmarks