Hello, I have been searching for hours trying to get this code to work. I am trying to get a pivot table to filter based on the value within a specific cell that will change often. When using the code below I get a run-time error '1004': "unable to set the currentPage property of the PivotField class". I have tried a few things I have found online with no luck. Any and all help is greatly appreciated.
--------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("G41:G41")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
Set pt = Worksheets("DATA_SOURCE").PivotTables("TESTING")
Set Field = pt.PivotFields("[Table2].[ID #].[ID #]")
NewCat = Worksheets("DATA_SOURCE").Range("G41").Value
With Field
.ClearAllFilters
.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub
--------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("G41:G41")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
Set pt = Worksheets("DATA_SOURCE").PivotTables("TESTING")
Set Field = pt.PivotFields("[Table2].[ID #].[ID #]")
NewCat = Worksheets("DATA_SOURCE").Range("G41").Value
With Field
.ClearAllFilters
.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub