Macro to Toggle Value Filters in PivotTable

TheMacroNoob

New Member
Joined
Aug 5, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am only just getting started with macros in excel and I am not sure how to create a macro to enable an action if not enabled, and disable an action if enabled.

I can record macro and complete my action, and then record another to reverse, but I would love to have some guidance on how to write a macro that does both.

There are two actions I would like to perform:
First:

In the PivotTable dropdown: Value Filters > Top 10... > Top 10 Items by "Total Incurred".
1659738642886.png
1659738659152.png

Second:

Then, once the button is hit again, I would like it to "Clear Filter".
Ideally, the button would filter all pivot tables in Active Sheet.

Is there a simple solution to this? Could anyone point me in the direction of a resource to learn how?

Thank you for your time.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

BSALV

Banned user
Joined
Oct 31, 2010
Messages
1,651
Office Version
  1. 365
  2. 2013
  3. 2007
only a suggestion, use a slicer, that works smoother without VBA.

EDIT: Wrong answer if it's for top-10
I suggest you use the macro-recorder and afterwards adapt it.
 

Forum statistics

Threads
1,176,613
Messages
5,904,020
Members
435,068
Latest member
StacyJ01

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
Top