VBA - Copy Pivot Filters From Specified Pivot Table to all Other Pivot Tables on Worksheet with Matching Filter Titles

wakerider017

Board Regular
Joined
Jun 10, 2015
Messages
77
Exactly what the thread title says.

I want to copy the pivot filters from PivotTable1 to all other pivot tables on the sheet with matching filter titles.

I want this to occur after the click of a button.


I found this code on Contextures from Jeff Weir, but it is not working for me. Any ideas?

Code:
[SIZE=2][FONT=arial][COLOR=#1A1A1A]Sub SetToAll()[/COLOR]
[COLOR=#1A1A1A]Dim pt As PivotTable[/COLOR]
[COLOR=#1A1A1A]Dim pf As PivotField[/COLOR]
[COLOR=#1A1A1A]Set pt = ActiveSheet.PivotTables(1)[/COLOR]
[COLOR=#1A1A1A]For Each pf In pt.PivotFields[/COLOR]
[COLOR=#1A1A1A]pf.ClearAllFilters[/COLOR]
[COLOR=#1A1A1A]Next[/COLOR]
[COLOR=#1A1A1A]End Sub[/COLOR][/FONT][/SIZE]
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I did something slightly more simple...


Code:
Sub CopyFilterAll()

Call CopyFilter1
Call CopyFilter2

End Sub


Code:
Sub CopyFilter1()

Dim filter1 As String

filter1 = ActiveSheet.PivotTables("PivotTable1").PivotFields("Week Ending").CurrentPage

ActiveSheet.PivotTables("PivotTable2").PivotFields("Week Ending").CurrentPage = filter1
ActiveSheet.PivotTables("PivotTable3").PivotFields("Week Ending").CurrentPage = filter1
ActiveSheet.PivotTables("PivotTable4").PivotFields("Week Ending").CurrentPage = filter1
ActiveSheet.PivotTables("PivotTable6").PivotFields("Week Ending").CurrentPage = filter1
ActiveSheet.PivotTables("PivotTable9").PivotFields("Week Ending").CurrentPage = filter1
ActiveSheet.PivotTables("PivotTable7").PivotFields("Week Ending").CurrentPage = filter1

End Sub


Code:
Sub CopyFilter2()

Dim filter2 As String

filter2 = ActiveSheet.PivotTables("PivotTable1").PivotFields("Fac ID").CurrentPage

ActiveSheet.PivotTables("PivotTable2").PivotFields("Fac ID").CurrentPage = filter2
ActiveSheet.PivotTables("PivotTable3").PivotFields("Fac ID").CurrentPage = filter2
ActiveSheet.PivotTables("PivotTable4").PivotFields("Fac ID").CurrentPage = filter2
ActiveSheet.PivotTables("PivotTable5").PivotFields("Fac ID").CurrentPage = filter2
ActiveSheet.PivotTables("PivotTable6").PivotFields("Fac ID").CurrentPage = filter2
ActiveSheet.PivotTables("PivotTable9").PivotFields("Fac ID").CurrentPage = filter2
ActiveSheet.PivotTables("PivotTable7").PivotFields("Fac ID").CurrentPage = filter2

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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