Change Pivot table filter with macro

swishtut

New Member
Joined
Mar 10, 2009
Messages
1
Hi
I have a pivot table with four items in an autofilter. A,F,N,M.
I want to have buttons on the dashboard that the user can click that will set the autofilter for three pivot charts to either A, or N, or M, or F.

I went in and selected show all. I then created a macro by select A, stopped the recording, went back and selected show all again and did the same for N, M, and F. The problem is when I select A, if it isn't in the show all state, I get an error. The same for all the others. Here's the error for F. The bottom line of code for "N is in yellow.

ActiveWindow.Visible = False
Windows("Force Protection - Corporate.xls").Activate
ActiveSheet.ChartObjects("Chart 38").Activate
With ActiveChart.PivotLayout.PivotTable.PivotFields("Service")
.PivotItems("A").Visible = False
.PivotItems("M").Visible = False
.PivotItems("N").Visible = False

How can I make the code work for every possible iteration of the autofilter. Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,203,483
Messages
6,055,679
Members
444,807
Latest member
RustyExcel

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