Adding same filter to multipe Pivot tables (different data sources) using VBA

Linesss

New Member
Joined
Nov 6, 2014
Messages
10
Hi,

I need 4 pivot tables to set their criteria to match cell A1.

I have below code which is working great for the first pivot (Pivottabel2), but how do I add Pivottabel3, Pivottabel4 and Pivottabel1:
_______

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub


Dim pt As PivotTable
Set pt = Worksheets("Fravær spec").PivotTables("Pivottabel2")


pt.ClearAllFilters
pt.PivotFields("personnummer").PivotFilters.Add Type:=xlCaptionContains, Value1:=Range("A1").Text


End Sub
_______

Thank you for your time :biggrin:
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Solution found :)


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub


Dim pt As PivotTable
For Each pt In Worksheets("Fravær spec").PivotTables


pt.ClearAllFilters
pt.PivotFields("personnummer").PivotFilters.Add Type:=xlCaptionContains, Value1:=Range("A1").Text
Next


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,637
Members
449,461
Latest member
kokoanutt

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