Dynamically Update Slicer Selection based on pivot table filtering

novicev

New Member
Joined
Jul 13, 2019
Messages
1
[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
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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top