Private Sub ComboBox1_DropButtonClick()
Static DisableCB1 As Boolean
Dim PItem As PivotItem
Application.ScreenUpdating = False
If DisableCB1 = False Then
ComboBox1.Clear
ComboBox1.AddItem "(All)"
For Each PItem In Worksheets("Sheet1").PivotTables("PivotTable1").PageFields("Country").PivotItems
ComboBox1.AddItem PItem.Name
Next PItem
DisableCB1 = True
Else
DisableCB1 = False
End If
Application.ScreenUpdating = True
End Sub
Private Sub ComboBox1_Change()
If ComboBox1.ListCount = 0 Then Exit Sub
Application.ScreenUpdating = False
Worksheets("Sheet1").PivotTables(1).PageFields("Country").CurrentPage = ComboBox1.Value
Application.ScreenUpdating = True
End Sub
Private Sub ComboBox2_DropButtonClick()
Static DisableCB2 As Boolean
Dim Sh As Worksheet
Dim PT As PivotTable
Dim PF As PivotField
Dim Rng1 As Range
Dim Rng2 As Range
Dim Page1 As String
Dim PItem As PivotItem
Dim Formula As String
Dim ShowItem As Boolean
Set Sh = Worksheets("Sheet1")
Set PT = Sh.PivotTables("PivotTable1")
Set PF = PT.PivotFields("Business")
Set Rng1 = Sh.Range("A1:A1000")
Set Rng2 = Sh.Range("B1:B1000")
Page1 = PT.PivotFields("Country").CurrentPage.Name
Application.ScreenUpdating = False
If DisableCB2 = False Then
ComboBox2.Clear
ComboBox2.AddItem "(All)"
If Page1 = "(All)" Then
For Each PItem In PF.PivotItems
ComboBox2.AddItem PItem.Name
Next PItem
Else
For Each PItem In PF.PivotItems
Formula = "=SUMPRODUCT(--('" & Sh.Name & "'!" & Rng1.Address & "=""" & Page1 & """)"
Formula = Formula & ",--('" & Sh.Name & "'!" & Rng2.Address & "=""" & PItem.Name & """))>0"
ShowItem = Evaluate(Formula)
If ShowItem = True Then
ComboBox2.AddItem PItem.Name
End If
Next PItem
End If
DisableCB2 = True
Else
DisableCB2 = False
End If
Application.ScreenUpdating = True
End Sub
Private Sub ComboBox2_Change()
If ComboBox1.ListCount = 0 Then Exit Sub
Application.ScreenUpdating = False
On Error Resume Next
Worksheets("Sheet1").PivotTables(1).PageFields("Business").CurrentPage = ComboBox2.Value
Application.ScreenUpdating = True
End Sub
Private Sub ComboBox3_DropButtonClick()
Static DisableCB3 As Boolean
Dim Sh As Worksheet
Dim PT As PivotTable
Dim PF As PivotField
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range
Dim Page1 As String
Dim Page2 As String
Dim PItem As PivotItem
Dim Formula As String
Dim ShowItem As Boolean
Set Sh = Worksheets("Sheet1")
Set PT = Sh.PivotTables("PivotTable1")
Set PF = PT.PivotFields("Function")
Set Rng1 = Sh.Range("A1:A1000")
Set Rng2 = Sh.Range("B1:B1000")
Set Rng3 = Sh.Range("C1:C1000")
Page1 = PT.PivotFields("Country").CurrentPage.Name
Page2 = PT.PivotFields("Business").CurrentPage.Name
Application.ScreenUpdating = False
If DisableCB3 = False Then
ComboBox3.Clear
ComboBox3.AddItem "(All)"
If Page1 = "(All)" Then
If Page2 = "(All)" Then
For Each PItem In PF.PivotItems
ComboBox3.AddItem PItem.Name
Next PItem
Else
For Each PItem In PF.PivotItems
Formula = "=SUMPRODUCT(--('" & Sh.Name & "'!" & Rng2.Address & "=""" & Page2 & """)"
Formula = Formula & ",--('" & Sh.Name & "'!" & Rng3.Address & "=""" & PItem.Name & """))>0"
ShowItem = Evaluate(Formula)
If ShowItem = True Then
ComboBox3.AddItem PItem.Name
End If
Next PItem
End If
Else
If Page2 = "(All)" Then
For Each PItem In PF.PivotItems
Formula = "=SUMPRODUCT(--('" & Sh.Name & "'!" & Rng1.Address & "=""" & Page1 & """)"
Formula = Formula & ",--('" & Sh.Name & "'!" & Rng3.Address & "=""" & PItem.Name & """))>0"
ShowItem = Evaluate(Formula)
If ShowItem = True Then
ComboBox3.AddItem PItem.Name
End If
Next PItem
Else
For Each PItem In PF.PivotItems
Formula = "=SUMPRODUCT(--('" & Sh.Name & "'!" & Rng1.Address & "=""" & Page1 & """)"
Formula = Formula & ",--('" & Sh.Name & "'!" & Rng2.Address & "=""" & Page2 & """)"
Formula = Formula & ",--('" & Sh.Name & "'!" & Rng3.Address & "=""" & PItem.Name & """))>0"
ShowItem = Evaluate(Formula)
If ShowItem = True Then
ComboBox3.AddItem PItem.Name
End If
Next PItem
End If
End If
DisableCB3 = True
Else
DisableCB3 = False
End If
Application.ScreenUpdating = True
End Sub
Private Sub ComboBox3_Change()
If ComboBox1.ListCount = 0 Then Exit Sub
Application.ScreenUpdating = False
On Error Resume Next
Worksheets("Sheet1").PivotTables(1).PageFields("Function").CurrentPage = ComboBox3.Value
Application.ScreenUpdating = True
End Sub