Please help. This is not working as intended. I tried "Err" and "Error" but they do not work.
Thank you.
Sub Filter_Pivot_Actual()
'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("Var to PY").PivotTables("VartoPY")
Set Field = pt.PivotFields("EntityName")
NewCat = Worksheets("Var to PY").Range("c1").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
If (Field.CurrentPage = NewCat) = Error Then GoTo 1 Else GoTo 5
1: Field.CurrentPage = NewCat
2: Sheets("Var to PY").Delete
3: Exit Sub
4: GoTo 12
5: Field.CurrentPage = NewCat
6: Field.EnableItemSelection = False
7: Application.CellDragAndDrop = True
8: ActiveWorkbook.ShowPivotTableFieldList = False
9: ActiveFilters.Application.PivotTableSelection = False
10: Worksheets("Var to PY").Protect Password:="xxx"
11: End With
12: End Sub
Thank you.
Sub Filter_Pivot_Actual()
'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("Var to PY").PivotTables("VartoPY")
Set Field = pt.PivotFields("EntityName")
NewCat = Worksheets("Var to PY").Range("c1").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
If (Field.CurrentPage = NewCat) = Error Then GoTo 1 Else GoTo 5
1: Field.CurrentPage = NewCat
2: Sheets("Var to PY").Delete
3: Exit Sub
4: GoTo 12
5: Field.CurrentPage = NewCat
6: Field.EnableItemSelection = False
7: Application.CellDragAndDrop = True
8: ActiveWorkbook.ShowPivotTableFieldList = False
9: ActiveFilters.Application.PivotTableSelection = False
10: Worksheets("Var to PY").Protect Password:="xxx"
11: End With
12: End Sub