Macro to Toggle Value Filters in PivotTable

TheMacroNoob

Board Regular
Joined
Aug 5, 2022
Messages
52
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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,795
Members
449,048
Latest member
greyangel23

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