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>
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>