ChickenTenderer
New Member
- Joined
- May 15, 2021
- Messages
- 2
- Office Version
- 2019
- Platform
- Windows
Hello world,
I have a sheet containing a bunch of PivotTables and graphs. The sheet has an area (B2:F2) where users can input filter criteria which when applied, will automatically filter the graphs displayed to the user.
For my data, there are literally tens of thousands of different PivotItems to choose from. Usually traditional methods such as looping through and marking the visible field as true or false for each one takes too long and is a terrible user experience.
I've been looking to use PivotField.CurrentPage which appears to work quicker, but can only seem to accept one PivotItem instead of multiple which in my case is the value in F2. I would really appreciate any assistance on this, as this is the last hurdle standing in the way of this sheet being complete.
Thanks in advance!
Note: the main part of the code I need help with is at the bottom in the IF statement.
Code:
I have a sheet containing a bunch of PivotTables and graphs. The sheet has an area (B2:F2) where users can input filter criteria which when applied, will automatically filter the graphs displayed to the user.
For my data, there are literally tens of thousands of different PivotItems to choose from. Usually traditional methods such as looping through and marking the visible field as true or false for each one takes too long and is a terrible user experience.
I've been looking to use PivotField.CurrentPage which appears to work quicker, but can only seem to accept one PivotItem instead of multiple which in my case is the value in F2. I would really appreciate any assistance on this, as this is the last hurdle standing in the way of this sheet being complete.
Thanks in advance!
Note: the main part of the code I need help with is at the bottom in the IF statement.
Code:
VBA Code:
Sub ApplyFilter()
Dim PivotTableArray() As Variant
Dim PT As PivotTable
Dim PTField As PivotField
Dim PortFilters() As Variant
'POPULATE PIVOTTABLE ARRAY
PivotTableArray = Array(Worksheets("MAIN").PivotTables("AppPTBytes"), Worksheets("MAIN").PivotTables("AppPTCount"))
'B2:F2 ARE RANGES FOR USERS TO ADD THEIR FILTERING CRITERIA
PortFilters = Array(Worksheets("MAIN").Range("B2").Text, Worksheets("MAIN").Range("C2").Text, Worksheets("MAIN").Range("D2").Text, Worksheets("MAIN").Range("E2").Text, Worksheets("MAIN").Range("[B]F2[/B]").Text)
Application.ScreenUpdating = False
Application.Calculation = xlManual
Application.EnableEvents = False
For Each pvtTable In PivotTableArray
'DESTINATION PORT FILTERS
Set PTField = pvtTable.PivotFields("Destination Port")
PTField.ClearAllFilters
For Each port In PortFilters
'G2 does a COUNTA statement to check if the user has added any filter criteria on the worksheet. If it's empty, then display all items in the filter
If Range("G2").Value = 0 Then
PTField.CurrentPage = "(All)"
Else
PTField.CurrentPage = port
End If
Next port
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub