Hi, I have a Macro that changes the filter on a Pivot Table based on a cell value. It works fine if I click in the cell and hit Enter, then the PT updates.
What I want is for it to work when the reference cell changes based on the selection of a separate Slicer (which is connected to a different PT), Here is my code:
What I want is for it to work when the reference cell changes based on the selection of a separate Slicer (which is connected to a different PT), Here is my code:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
If Intersect(Target, Range("AL1:AL2")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("PT's").PivotTables("PivotTable3")
Set Field = pt.PivotFields("FinancialYear")
NewCat = Worksheets("PT's").Range("AL1").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub