[COLOR=#BBC0C4 !important][COLOR=#6A737C !important]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.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;"> Sub filtermonth()
'
' filtermonth Macro
ActiveSheet.PivotTables("PivotTable4").PivotFields("Month").ClearAllFilters
ActiveSheet.PivotTables("PivotTable4").PivotFields("Month").PivotFilters.Add2 _
Type:=xlValueDoesNotEqual, DataField:=ActiveSheet.PivotTables("PivotTable4" _
).PivotFields("Actuals"), Value1:=0
End Sub</code>I am getting the below error when i run this
[/COLOR]
6
[/COLOR]
Not sure if it makes any difference but I am using MS office Professional Plus 2016
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.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;"> Sub filtermonth()
'
' filtermonth Macro
ActiveSheet.PivotTables("PivotTable4").PivotFields("Month").ClearAllFilters
ActiveSheet.PivotTables("PivotTable4").PivotFields("Month").PivotFilters.Add2 _
Type:=xlValueDoesNotEqual, DataField:=ActiveSheet.PivotTables("PivotTable4" _
).PivotFields("Actuals"), Value1:=0
End Sub</code>I am getting the below error when i run this
Run time error 1004: Unable to get the PivotFields property of the PivotTable Class
[/COLOR]
6
[/COLOR]
Not sure if it makes any difference but I am using MS office Professional Plus 2016