muhleebbin
Active Member
- Joined
- Sep 30, 2017
- Messages
- 252
- Office Version
- 365
- 2019
- 2016
- 2013
- 2010
- Platform
- Windows
- MacOS
- Mobile
- Web
Hi!
I have the following code however on occasion I do run into an error when the pivot field (cat) that the code is looking for does not exist. Can someone help with the error handling code that would eliminate this?
Thank you in advance!
I have the following code however on occasion I do run into an error when the pivot field (cat) that the code is looking for does not exist. Can someone help with the error handling code that would eliminate this?
Thank you in advance!
VBA Code:
Dim pt As PivotTable
Dim field As PivotField
Dim res As PivotField
Dim cat As String
Application.ScreenUpdating = False
Set pt = Worksheets("MIR Pivot").PivotTables("PivotTable1")
Set field = pt.PivotFields("PropertyName")
Set res = pt.PivotFields("Resident")
cat = Worksheets("MIR Pivot").Range("G2").Value
With pt
field.ClearAllFilters
field.CurrentPage = cat
pt.RefreshTable
End With