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 am currently working on this code I found on a different forum. 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
ForEach WS In aWB.Worksheets
ForEach myPivot In WS.PivotTables
Set myPivotField =Nothing
OnErrorResumeNext
Set myPivotField = myPivot.PivotFields(“Style”)
myPivotField.CurrentPage =“Style”
Next myPivot
Next WS
EndSub
</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
EndWith
Else
With ThisWorkbook.PivotTables
Let s =.Item("PivotTable2").PivotFields("Style").CurrentPage
.Item("PivotTable1").PivotFields("Style").ClearAllFilters
.Item("PivotTable1").PivotFields("Style").CurrentPage = s
EndWith
EndIf
Application.EnableEvents =True
EndSub</code>
I am currently working on this code I found on a different forum. 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
ForEach WS In aWB.Worksheets
ForEach myPivot In WS.PivotTables
Set myPivotField =Nothing
OnErrorResumeNext
Set myPivotField = myPivot.PivotFields(“Style”)
myPivotField.CurrentPage =“Style”
Next myPivot
Next WS
EndSub
</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
EndWith
Else
With ThisWorkbook.PivotTables
Let s =.Item("PivotTable2").PivotFields("Style").CurrentPage
.Item("PivotTable1").PivotFields("Style").ClearAllFilters
.Item("PivotTable1").PivotFields("Style").CurrentPage = s
EndWith
EndIf
Application.EnableEvents =True
EndSub</code>