Loop through visible Slicers on Active Sheet

JimMatthews

New Member
Joined
Aug 12, 2014
Messages
9
Hi

I want to write a macro that gets the name of all the slicers on the active sheet. I have written this code, and that seems to loop through all the slicers in the book, not the sheet. I want to just find the ones on the active sheet.

Code:
Sub FindSlicers()
    Dim mySlicer As SlicerCache
    
    For Each mySlicer In ActiveWorkbook.SlicerCaches
        x = mySlicer.Name
    Next mySlicer
    
End Sub

Any help appreciated
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try:

Code:
Sub FindSlicers()
    Dim myCache As SlicerCache
    Dim mySlicer As Slicer
    For Each myCache In ActiveWorkbook.SlicerCaches
        For Each mySlicer In myCache.Slicers
            If mySlicer.Shape.TopLeftCell.Worksheet.Name = ActiveSheet.Name Then
            MsgBox mySlicer.Name
            End If
        Next mySlicer
    Next myCache
End Sub
 
Upvote 0
I am using this and it works to a degree....

I have 6 slicers in the active sheet, but the above is only returning 5 of them.

Is there a setting on each of the slicers that allows it to be visible or not?


Apologies, I didn't allow the code to complete and the 6th wasn't 'next' to the initial 5 it found!!

Works perfectly!!!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,245
Members
448,555
Latest member
RobertJones1986

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