I have a worksheet with 2 pivot tables with criteria options of Apple or Orange. There is a separate drop down combo box with 2 options: Apple and Orange. My goal is to have the value in the combo box change the criteria of both pivot tables. Right now, the combination box sets the value of cell C1. If the user selects “Orange”, then cell C1 displays the number 2. Cell B1 has an index function to lookup the corresponding word out of a table on a separate sheet from the number in C1:
=index('Data table 1'!A5:A6,C1)
I use the following code to try and change the pivot table:
This code works when I double click cell B1 and then press enter. It does not work by itself.
Any ideas on how to get this to work?
=index('Data table 1'!A5:A6,C1)
I use the following code to try and change the pivot table:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim pt As PivotTable
Dim pt2 As PivotTable
If Not Intersect(Target(1, 1), Range("b1")) Is Nothing Then
Set pt = Me.PivotTables("PivotTable1")
With pt
.RefreshTable
.PivotFields("Fruit").CurrentPage = Range("b1").Value
Set pt2 = Me.PivotTables("PivotTable2")
End With
With pt2
.RefreshTable
.PivotFields("Fruit").CurrentPage = Range("b1").Value
End With
End If
End Sub
This code works when I double click cell B1 and then press enter. It does not work by itself.
Any ideas on how to get this to work?