VBA Filter Pivot Tables on different sheets

Status
Not open for further replies.

joejs

New Member
Joined
Mar 22, 2019
Messages
6
I have 2 different pivot tables on different Excel sheets using different data sources. They both have a "Style" column that can be filtered. When I filter for style on one pivot table I want the other pivot table to automatically (or with a button) filter for those same selected styles. I was wondering if anyone could give me some assistance. Thanks!
I am currently working on this code. In the objects section in VBA I have:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub ChangePivotFilter()
Dim WS As Excel.Worksheet
Dim aWB As Excel.Workbook
Dim myPivot As Excel.PivotTable
Dim myPivotField As Excel.PivotField
Set aWB = ActiveWorkbook
For Each WS In aWB.Worksheets
For Each myPivot In WS.PivotTables

Set myPivotField = Nothing

On Error Resume Next

Set myPivotField = myPivot.PivotFields(“Style”)

myPivotField
.CurrentPage = “Style”

Next myPivot

Next WS

End Sub</code>In the module section in VBA I have:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub Button1_Click()

Dim s$

Application
.EnableEvents = False

If Target.Name = "PivotTable1" Then
With ThisWorkbook.PivotTables
Let s = .Item("PivotTable1").PivotFields("Style").CurrentPage
.Item("PivotTable2").PivotFields("Style").ClearAllFilters
.Item("PivotTable2").PivotFields("Style").CurrentPage = s
End With
Else
With ThisWorkbook.PivotTables
Let s = .Item("PivotTable2").PivotFields("Style").CurrentPage
.Item("PivotTable1").PivotFields("Style").ClearAllFilters
.Item("PivotTable1").PivotFields("Style").CurrentPage = s
End With
End If

Application
.EnableEvents = True

End Sub

</code>
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Duplicate https://www.mrexcel.com/forum/excel...pivot-tables-vba-post5247449.html#post5247449

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

If you do not receive a response, you can "bump" it by replying to it again, though we advise you to wait 24 hours before doing and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,523
Messages
6,120,038
Members
448,940
Latest member
mdusw

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