VBA to clear all slicer filters

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have a very simple code where when i click i want VBA code to first clear all filters in the slicer then select RB. Below is the code i am using but no success. can anyone help?



ActiveWorkbook.SlicerCaches("Slicer_Manufacturer1").ClearManualFilter

With ActiveWorkbook.SlicerCaches("Slicer_Manufacturer1")
.SlicerItems("RB").Selected = True

End With
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You may do something like
Code:
Dim objSlicer As SlicerCache
For Each objSlicer In ActiveWorkbook.SlicerCaches
     If objSlicer.Name <> "RB" Then objSlicer.ClearManualFilter
Next objSlicer

I am thinking why would you leave "RB" out and clear all the others. I have not tried this code so don't know if it works, especially objSlicer.Name portion.
I am just trying to give you an idea.
 
Last edited:
Upvote 0
Hi Korhan,

Code cleared all the filters in 8 slicers but under Maufacturer1 slicer it didnt select RB. Can you please help.

Thanks
 
Upvote 0
Well, try this. I am not how your data is named under your slicers. I have tested this on my computer and it works.
Code:
Sub SlicerTest()


    Dim objSlicer As SlicerCache
    
    For Each objSlicer In ActiveWorkbook.SlicerCaches
         If objSlicer.Name <> "RB" Then objSlicer.ClearManualFilter
    Next objSlicer
    
    ' Select a certain filter on a slicer
    With ActiveWorkbook.SlicerCaches("Slicer_Manufacturer1")
        
        For i = 1 To .SlicerItems.Count
            If .SlicerItems(i).Caption Like "RB" Then
                .SlicerItems(i).Selected = True
            Else
                .SlicerItems(i).Selected = False
            End If
        Next i
    End With
    
End Sub
 
Upvote 0
This is what i tried and still couldn't get it to work. It clears all filters but not selecting Reckitt Benckiser under Manufacturer1 slicer.

Sub RB()




Dim objSlicer As SlicerCache

For Each objSlicer In ActiveWorkbook.SlicerCaches
If objSlicer.Name <> "Reckitt Benckiser" Then objSlicer.ClearManualFilter
Next objSlicer

' Select a certain filter on a slicer
With ActiveWorkbook.SlicerCaches("Slicer_Manufacturer1")

For i = 1 To .SlicerItems.Count
If .SlicerItems(i).Caption Like "Reckitt Benckiser" Then
.SlicerItems(i).Selected = True
Else
.SlicerItems(i).Selected = False
End If
Next i
End With

End Sub
 
Upvote 0
Hey there,

Sorry for not getting back to you before. I was really busy. Were able to solve this issue?
 
Upvote 0
Hi Korhan,

yes I was able to get it to work. Thanks for your help. My last question is there a way to speed up the selection process...I have too many manufacturers listed and it takes very long time to run the code.

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,924
Messages
6,175,417
Members
452,640
Latest member
steveridge

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