blixamarkham
New Member
- Joined
- Aug 31, 2015
- Messages
- 5
Greetings. I have two cells that are both drop down lists referenced from a Vlookup Table. When One cell is "D11" for the "Group" and the other is "D12" for the "Campaign". When the user selects from the drop down cell what they want, I have 3 pivot tables that should change their filter based on the drop down selected. My code works fine for a single cell but when I tried to extend it to two different cells it won't run. I have done research and know I probably have to use Intersect somewhere but that is about as far as I have gotten. The excel file is over 50MB so posting the file will not be feasible. Anyone who helps, thank you for your time. Here is the code:
My working code for 1 cell:
My attempt at extending my code to two different cells.
My working code for 1 cell:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = Range("D13").Address Then Exit Sub
Dim pt As PivotTable
Dim ptItem As PivotItem
On Error GoTo CleanUp
Application.EnableEvents = False
For Each pt In Worksheets("ClosedLoansAll").PivotTables
With pt.PivotFields("Campaign")
If .EnableMultiplePageItems = True Then
.ClearAllFilters
End If
If LCase$(Target.Value) = "all" Then
.ClearAllFilters
Else
Set ptItem = .PivotItems(Target.Value)
If Not ptItem Is Nothing Then
.CurrentPage = Target.Value
End If
End If
End With
Next
CleanUp:
Application.EnableEvents = True
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' If Not Target.Address = Range("D12").Address Then Exit Sub
' If Not Target.Address = Range("D11").Address Then Exit Sub
Dim pt As PivotTable
Dim ptItem As PivotItem
On Error GoTo CleanUp
Application.EnableEvents = False
For Each pt In Worksheets("ClosedLoansByBranch").PivotTables
Target.Address = Range("D12").Address
If Not Intersect(Target, Range("D12")) Is Nothing Then
With pt.PivotFields("Campaign")
' If Not Target.Address = Range("D12").Address Then Exit Sub
If .EnableMultiplePageItems = True Then
.ClearAllFilters
End If
If LCase$(Target.Value) = "all" Then
.ClearAllFilters
Else
Set ptItem = .PivotItems(Target.Value)
If Not ptItem Is Nothing Then
.CurrentPage = Target.Value
End If
End If
End With
Else
With pt.PivotFields("Group")
' If Not Target.Address = Range("D11").Address Then Exit Sub
If .EnableMultiplePageItems = True Then
.ClearAllFilters
End If
If LCase$(Target.Value) = "all" Then
.ClearAllFilters
Else
Set ptItem = .PivotItems(Target.Value)
If Not ptItem Is Nothing Then
.CurrentPage = Target.Value
End If
End If
End With
End If
Next
CleanUp:
Application.EnableEvents = True
End Sub