I've built several pivot tables to automate some reports but, I'm thinking there might be a better way in choosing multiple Pivot items. Is there a way to setup an array and have the pivot items visible if they are in the array? I've never used arrays. My current code works fine for my current table but, my next table will have mega ElseIf statements in it unless there is a better way.
Dim PVI as PivotItem
Set PF = pt.PivotFields("Task")
PF.Orientation = xlRowField
For Each PVI In ActiveSheet.PivotTables("SIMS").PivotFields("Task").PivotItems
If PVI Like "LP 11A" Or PVI Like "LP 11A" & "*" Then
PVI.Visible = True
ElseIf PVI Like "LP 12A" Or PVI Like "LP 12A" & "*" Then
PVI.Visible = False
ElseIf PVI Like "LP 12" Or PVI Like "LP 12" & "*" Then
PVI.Visible = True
ElseIf PVI Like "LP 15A" Or PVI Like "LP 15A" & "*" Then
PVI.Visible = True
ElseIf PVI Like "LP 16A" Or PVI Like "LP 16A" & "*" Then
PVI.Visible = False
ElseIf PVI Like "LP 16" Or PVI Like "LP 16" & "*" Then
PVI.Visible = True
Else:
PVI.Visible = False
End If
Next
Bookmarks