Trying to run the below macro to change a pivot table based on a cell and this keeps erroring out?
Field.CurrentPage = NewCat
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cells are touched
If Intersect(Target, Range("F4:G4")) 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. Assigns input cell value to the PT on another tab.
Set pt = Worksheets("EVM Summary Level").PivotTables("VLQP")
Set Field = pt.PivotFields("EVM Name")
NewCat = Worksheets("EVM Summary Level").Range("K18").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub
Field.CurrentPage = NewCat
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cells are touched
If Intersect(Target, Range("F4:G4")) 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. Assigns input cell value to the PT on another tab.
Set pt = Worksheets("EVM Summary Level").PivotTables("VLQP")
Set Field = pt.PivotFields("EVM Name")
NewCat = Worksheets("EVM Summary Level").Range("K18").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub