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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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