VBA code to Clear All Slicers in Excel 365 except one/two

hananak

Board Regular
Joined
Feb 10, 2022
Messages
110
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Dear All,

I have a 3 sheets in a workbook with many slicers and it is pain to clear them one by one and then reselect every time to do various analysis. There is only one/two slicers that will have fixed values.

I am looking for a VBA code, which will be assigned to a button. on clicking it, it should clear all slicers except that one/two.

Your help would be appreciated.

Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi as each slicer has a name you can look to hide them or unhide as necessary. Take a look at this thread where I am using an if statement and others that joined in suggested some alternative methods to hide them.

You can manually reset all slicers via the Insert tab and under buttons select Clear All Slicers. You could record a macro to reset all which should provide the code.

Post in thread 'VBA code to hide and unhide all the Slicers in workbook.' VBA code to hide and unhide all the Slicers in workbook.
 
Last edited:
Upvote 0
Here is an example to reset all slicers:

VBA Code:
Sub AllslicersReset()
Dim oSlrC As SlicerCache

For Each oSlrC In ActiveWorkbook.SlicerCaches
    oSlrC.ClearManualFilter
Next oSlrC
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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