I found the following code at: http://www.contextures.com/excelfiles.html which allows an Excel user to change a page field in a main pivot table, and the same selections are made in all pivot tables that contain the same page fields. The code is as follows:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
On Error Resume Next
Dim ws As Worksheet
Dim wsMain As Worksheet
Dim ptMain As PivotTable
Dim pt As PivotTable
Dim pfMain As PivotField
Dim pi As PivotItem
Dim pf As PivotField
On Error Resume Next
Set wsMain = Sheets("AE Pivot")
Set ptMain = Target
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each pfMain In ptMain.PageFields
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
For Each pf In pt.PageFields
If pf.Name = pfMain.Name Then
If pfMain.CurrentPage = "(All)" Then
pf.CurrentPage = "(All)"
Exit For
End If
For Each pi In pf.PivotItems
If pi.Name = pfMain.CurrentPage Then
pf.CurrentPage = pi.Name
Exit For
End If
Next pi
End If
Next pf
Next pt
Next ws
Next pfMain
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
The routine works great when you only select one item in the Page Field (i.e. "All" or another single value in the Page Field)
Moving forward, I would like to put a page field in my main pivot table and do a multi-select on the filter and have the other page fields update with my multi select. Anotherwards, I may have a 7 item page field and I choose 5 of the 7 fields. I would then like page fields in my other pivot tables to update with the multi-select "filter" (5 fields selected).
Is this even possible or am I stuck using the code above? I am using Excel 2007 btw.
Thanks in advance.
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
On Error Resume Next
Dim ws As Worksheet
Dim wsMain As Worksheet
Dim ptMain As PivotTable
Dim pt As PivotTable
Dim pfMain As PivotField
Dim pi As PivotItem
Dim pf As PivotField
On Error Resume Next
Set wsMain = Sheets("AE Pivot")
Set ptMain = Target
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each pfMain In ptMain.PageFields
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
For Each pf In pt.PageFields
If pf.Name = pfMain.Name Then
If pfMain.CurrentPage = "(All)" Then
pf.CurrentPage = "(All)"
Exit For
End If
For Each pi In pf.PivotItems
If pi.Name = pfMain.CurrentPage Then
pf.CurrentPage = pi.Name
Exit For
End If
Next pi
End If
Next pf
Next pt
Next ws
Next pfMain
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
The routine works great when you only select one item in the Page Field (i.e. "All" or another single value in the Page Field)
Moving forward, I would like to put a page field in my main pivot table and do a multi-select on the filter and have the other page fields update with my multi select. Anotherwards, I may have a 7 item page field and I choose 5 of the 7 fields. I would then like page fields in my other pivot tables to update with the multi-select "filter" (5 fields selected).
Is this even possible or am I stuck using the code above? I am using Excel 2007 btw.
Thanks in advance.