So I have multiple pivot tables on a single sheet in excel. I have a long list of months in the row labels. The report filter is filterable by names. All of the columns in the pivots are just sums of data.
What I’m looking for (and I’m guessing a macro is the only way to do it), is a way to be able to change the filters of one of the pivots on that sheet and it update the other pivots on only that sheet to mimic the filters (both report and row label) of the one that I changed. Nothing else should change in the other pivot tables – just the filters.
Unfortunately, I literally know nothing about coding vba (I know a bit of java and stuff but I’ve never done any macro coding). I was able to copy a macro from the internet that did part of what I need; it updates the report filter but doesn’t update the dates in the row label filter. Here’s the coding for that:
Option Explicit
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
On Error Resume Next
Dim wsMain As Worksheet
Dim ws As Worksheet
Dim ptMain As PivotTable
Dim pt As PivotTable
Dim pfMain As PivotField
Dim pf As PivotField
Dim pi As PivotItem
Dim bMI As Boolean
On Error Resume Next
Set wsMain = ActiveSheet
Set ptMain = Target
Application.EnableEvents = False
Application.ScreenUpdating = False
'change all fields for all pivot tables on active sheet
For Each pfMain In ptMain.PageFields
bMI = pfMain.EnableMultiplePageItems
For Each pt In wsMain.PivotTables
If pt <> ptMain Then
pt.ManualUpdate = True
Set pf = pt.PivotFields(pfMain.Name)
bMI = pfMain.EnableMultiplePageItems
With pf
.ClearAllFilters
Select Case bMI
Case False
.CurrentPage = pfMain.CurrentPage.Value
Case True
.CurrentPage = "(All)"
For Each pi In pfMain.PivotItems
.PivotItems(pi.Name).Visible = pi.Visible
Next pi
.EnableMultiplePageItems = bMI
End Select
End With
bMI = False
Set pf = Nothing
pt.ManualUpdate = False
End If
Next pt
Next pfMain
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Is there anyway to do what I’m looking to do? Your help would be GREATLY appreciated!
Without seeing your pivottables it seems that all you need to do to the above code is repeat the steps from setting the pivotfield value to reflect the date. This is done by
adding a variant of the loop set up by the line:
to
the full code is below, i would also avoid on error resume next
try it and see if it works I have not tested this