I have 3 pivot tables using same source data. I have month wise budget and actual numbers (3 columns - Month, Budget, Actual).
I have created one slicer for month and only want to show months which have actual numbers(for example Jan to June). Right now, it is showing all the months as budget numbers are present for the entire year. How can I achieve this with VBA code?
As a first step, I have tried a value filter on the pivot table, but I am getting an error. My plan was to filter the pivot table with actual not equal to zero months first, and then to apply the selection of months to the slicer.
Sub filtermonth()
'
' filtermonth Macro
'
ActiveSheet.PivotTables("PivotTable4").PivotFields("Month").PivotFilters.Add2 _
Type:=xlValueDoesNotEqual, DataField:=ActiveSheet.PivotTables("PivotTable4" _
).PivotFields("Actuals"), Value1:=0
End Sub
I am getting the below error when i run this
Run time error 1004: Unable to get the PivotFields property of the PivotTable Class