Looking to Set All pivot table filter fields to same selection using VBA

Findrishabh

New Member
Joined
Feb 7, 2025
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi team,

I am comparatively new to VBA , however I keep trying to solve some ideas that come into my mind, recently I am trying to sync filter fields of 2 or more pivot tables using vba but I am not able to

I have currently two Pivot tables named "Dashboard1" on sheet1 and other "Dashboard2" on Sheet2,
they all have common filter field named "Time" which has time in intervals like "12:00:00", 01:30:00 and so on.

here is how my code looks
I am using this code on each sheet to call pivot table
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'If Target.Name = "Dashboard1" Then (this is for sheet 1)
' Call PivotFilters
' End If
'End Sub

similar change event on sheet 2 to call PivotFilters2

here is my sub (which changes to set pt1 value to pt2 and in sub 2 to set pt2 value to pt1)
Sub PivotFilters()

Dim ws1 As Worksheet, ws2 As Worksheet
Dim pt1 As PivotTable, pt2 As PivotTable
Dim filterfld As String, filterval As String

Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws2 = ThisWorkbook.Sheets("Sheet2")

Set pt1 = ws1.PivotTables("Dashboard1")
Set pt2 = ws2.PivotTables("Dashboard2")
filterfld = "Time"

If pt1.PivotFields(filterfld).CurrentPage <> "(All)" Then
filterval = pt1.PivotFields(filterfld).CurrentPage
Else
filterval = "(All)"
End If
pt2.PivotFields(filterfld).CurrentPage = filterval


End Sub


this currently allows only 1 selection under filter field "Time" but I want that whatever values selected in Pt1 should be applied to pt2 and vice versa on detecting change,

I have tried "EnableMultiplePageItems=true" but that does not work, please help me?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,226,463
Messages
6,191,181
Members
453,646
Latest member
BOUCHOUATA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top