I tried to change it to filter the Row Label instead:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim pt As PivotTable
Dim Field As PivotField
Dim A1Value As String
If Not Intersect(Target, Range("A1")) Is Nothing Then
Set pt = Worksheets("Sheet2").PivotTables("PivotTable1")
Set Field = pt.PivotFields("Test")
A1Value = Worksheets("Sheet1").Range("A1").Value
pt.ManualUpdate = True
With Field
.ClearAllFilters
.PivotFilters.Add Type:=xlValueEquals, Value:="A1Value"
End With
pt.RefreshTable
pt.ManualUpdate = False
End If
End Sub
But now I get a compile error "Named argument not found" at .PivotFilters.Add
I tried adding quotation on "A1Value" but with or without I'm getting same error.
I have the code in Sheet 1, and the Pivot table is in Sheet 2.
Bookmarks