Hi, I am tyring to create filter selection process using VBA macro, but for some reason, the value from a filtered field is not working. Please take a look at my code..
Code
Sub Step3Pivot()
Dim pt As PivotTable
Dim pf As PivotField
Dim Pi As PivotItem
Set pt = ActiveSheet.PivotTables("NetZero")
Set pf = pt.PivotFields("GL_xxxx")
pf.Orientation = xlPageField
Set pf = pt.PivotFields("CODE_xxx")
pf.Orientation = xlPageField
Set pf = pt.PivotFields("PA_NUM_xxx")
pf.Orientation = xlRowField
Set pf = pt.PivotFields("PA_PRO_xxx")
pf.Orientation = xlRowField
Set pf = pt.PivotFields("PA_TASK_xxx")
pf.Orientation = xlRowField
For Each Pi In ActiveSheet.PivotTables("NetZero").PivotFields("GL_xxxx").PivotItems
Select Case Pi.Name
'Case "B & L"
Case "Purchase"
'Case "Adjustment"
Case Else
Pi.Visible = False
End Select
Next Pi
End Sub
Display More
When I filter on "B & L", it works. However, when I try to filter the "Purchase" and "Adjustment" I get an error MSG of "Run-time error'1004': Unable to set the Visible property of the PivotItem class.
Please help..
Thanks!!
Moderator note: Please take a moment to review the rules regarding the use of code tags. I have added them for you this time, please use them in the future.