I think I've got it. Code below filters according to my ranges.
Set PT = ActiveSheet.PivotTables("PivotTable1")
'Restrict the data to what's shown in our "DivPAC" page
MyDat = Application.Transpose(WB.Sheets("DivPAC").Range("G6:G12").Value)
With PT.PivotFields("DEPTID")
.PivotItems(MyDat(1)).Visible = True
On Error Resume Next
For Each PI In .PivotItems
PI.Visible = UBound(Filter(MyDat, PI.Name)) >= 0
Next PI
End With
MyDat = Application.Transpose(WB.Sheets("DivPAC").Range("J40:J133").Value)
With PT.PivotFields("PROGRAM_CODE")
.PivotItems(MyDat(1)).Visible = True
On Error Resume Next
For Each PI In .PivotItems
PI.Visible = UBound(Filter(MyDat, PI.Name)) >= 0
Next PI
End With
I can also replace ""G6:G12" with my namedRange "DebbieDiv", like this:
MyDat = Application.Transpose(WB.Sheets("DivPAC").Range("DebbieDiv").Value)
. So the gets me closer to using the Analyst Name to filter the pivot. I already capture the first name of my analyst and define it as USER, so can use code like
MyDat = Application.Transpose(WB.Sheets("DivPAC").Range(User & "Div").Value)
That seems to be working for me so far.
So, all I need to do is create named ranges for each Analyst, and I should be golden. If you think of a better way I'm all open to that.
Bookmarks