hi all, i have set up a worksheet change event to use a certain value to then filter a pivot table. How do i tailor this to also use the second selection from the next cell to then filter the pivot table again? I have borrowed code from the contextures website to get this far:
my drop down cells are on the worksheet "Annual Results" in C2, and C3. my pivot table is on the tab entitled "Rep Sales Data". this pivot table has Sales Rep Name as a report filter and Debtor Normal Name as the first column of names.
so, at this stage, when the first selection is made of Account Manager (C2), the pivot report filter changes also. I want the Customer Groups to change also based on the selection at C3.
I have tried joining two of contextures models ("Selection Change event to change pivot table report filter" and "Pivot MultiPages Change All 2007") to get the second event firing but no luck so far. can anyone point me in the right direction to get me started again?
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RepSalesData As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strFieldName As String, strFieldGrp As String
' Dim critRange As Range
'Dim AnnResults As Worksheet
Set RepSalesData = Worksheets("Rep Sales Data")
Set AnnResults = Worksheets("Annual Results")
'Set critRange = AnnResults.Range("$C$2,$C$3")
strFieldName = "Sales Rep Name"
strFieldGrp = "Debtor Normal Name"
On Error Resume Next
With Application
.EnableEvents = False
.ScreenUpdating = False
'If Not (Application.Intersect(Target, critRange) Is Nothing) Then
If Target.Address = Range("c2").Address Then
With RepSalesData.PivotTables("PivotTableRepSaleData").PageFields(strFieldName)
For Each pi In .PivotItems
If pi.Value = Target.Value Then
.CurrentPage = Target.Value
Exit For
Else
.CurrentPage = "(All)"
End If
Next pi
End With
End If
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
my drop down cells are on the worksheet "Annual Results" in C2, and C3. my pivot table is on the tab entitled "Rep Sales Data". this pivot table has Sales Rep Name as a report filter and Debtor Normal Name as the first column of names.
so, at this stage, when the first selection is made of Account Manager (C2), the pivot report filter changes also. I want the Customer Groups to change also based on the selection at C3.
I have tried joining two of contextures models ("Selection Change event to change pivot table report filter" and "Pivot MultiPages Change All 2007") to get the second event firing but no luck so far. can anyone point me in the right direction to get me started again?