• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change multiple Pivot Table Filters based on Value entered into cell

Travis Frank

New Member
I am trying to update 2 pivot table filters based on a value I enter into a cell. I was able to find the code to perform this for a single pivot table But I would like to have both pivot table update. Any help is greatly appreciated.

WorkSheet: Pivot Tables
PivotTable#1: "LeadTime"
PivotTable#2: "Usage"
PivotField#1: "MCHP#"
PivotField#2: "MCHP #"


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 20180702
    Dim xPTable As PivotTable
    Dim xPFile As PivotField
    Dim xStr As String
    On Error Resume Next
    If Intersect(Target, Range("A1:A2")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xPTable = Worksheets("Pivot Tables").PivotTables("LeadTime")
    Set xPFile = xPTable.PivotFields("MCHP#")
    xStr = Target.Text
    xPFile.ClearAllFilters
    xPFile.CurrentPage = xStr
    Application.ScreenUpdating = True
End Sub
 
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 20180702
Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String
Dim Pvt As String

On Error Resume Next
If Intersect(Target, Range("A1:A2")) Is Nothing Then Exit Sub

Application.ScreenUpdating = False

For Each xPTable In Worksheets("Pivot Tables").PivotTables '(Loop through all PivotTable)

    Pvt = xPTable.Name

    If Pvt = "LeadTime" Or Pvt = "PivotTable1" Then '(Change this bit to whatever Pivots you want)
     
        Set xPTable = Worksheets("Pivot Tables").PivotTables(Pvt)
        Set xPFile = xPTable.PivotFields("MCHP#")
        xStr = Target.Text
        xPFile.ClearAllFilters
        xPFile.CurrentPage = xStr
     
    Else
    End If
 
Next xPTable

Application.ScreenUpdating = True

End Sub
 
Back
Top