Filtering row labels in pivot table using vba
13,102
It is clearly mentioned in the error, the name of the PivotField is incorrect.
The possibility is that the Name of the Pivot Field has been changed from "ToStateId". In order to find the appropriate name, please run the following code:
For each pField in ActiveSheet.PivotTables("PivotTable1").PivotFields
Debug.Print pField.Name
Next pField
Go to VBA Editor, press Ctrl+G, it will open the immediate window. It will show all the available pivot fields.Then please use the correct Pivot Field and try.
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I have searched a lot of forums but still haven't found the answer for this:
I am trying to filter my row label which varies from 1 to 10, in order to only show me 5 and 10.
I wrote the following code, but it produces error 1004 "Unable to get the PivotFields property of the PivotTable class".
ActiveWorkbook.Sheets("SideCalculations-KPIs").Activate With ActiveSheet.PivotTables("PivotTable1").PivotFields("ToStateId") .ClearAllFilters .PivotItems("5").Visible = True .PivotItems("10").Visible = True End With
thanks in advance