VBA: Clear Slicers From Specific Sheet or Active sheet

rubenidas

New Member
Joined
Aug 10, 2016
Messages
11
Hi,
I am trying to modify my code to clear the slicers from the active sheet only. I have two tabs with two different dashboards and just need the macro to clear the slicers depending which sheet I'm on. I tried adding the name of the sheet after ActiveWorkbook but no luck.

any help is appreciated!

Code:
Sub clearSlicers1()Application.ScreenUpdating = False


     Dim slicers As SlicerCache
  
    
  For Each slicers In ActiveWorkbook.SlicerCaches
  
      slicers.ClearManualFilter
       
    Next slicers
    


End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
If you have not renamed your slicer from the default name, how about something like this...

Code:
Sub clrSlicer()
    
    Dim sln
    Dim sct As Integer, i As Integer
    Dim ws As Worksheet: Set ws = ActiveSheet
    Dim wb As Workbook: Set wb = ThisWorkbook
    On Error Resume Next
    sct = wb.ActiveSheet.Shapes.Count
    For i = 1 To sct
        If wb.ActiveSheet.Shapes(i).Type = msoSlicer Then
            sln = wb.ActiveSheet.Shapes(i).Name
            wb.SlicerCaches.Item("Slicer_" & sln).ClearManualFilter
        End If
    Next
            
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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