• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to Loop through each Slicer in Worksheet and Change setting?

rumshar

Member
Hi Excel Masters,
I am trying to automate a process where I need to check each slicer in a Worksheet and change its setting. Basically I am trying to check box with 'hide items with no data' option in slicer setting. Any help with VBA would be highly appreciated. It needs to be done for all the slicers of all the worksheets.

Please see below image.

upload_2016-6-23_13-7-55.png
 
Some thing like below.

Code:
Sub Test()
Dim sCache As SlicerCache

For Each sCache In ActiveWorkbook.SlicerCaches
    sCache.CrossFilterType = xlSlicerCrossFilterHideButtonsWithNoData
Next sCache

MsgBox "All " & ActiveWorkbook.SlicerCaches.Count & " slicers updated", vbInformation
End Sub

Edit: FYI - This will not work if OLAP data sources. Use SlicerCacheLevel instead of SlicerCache. See link for more info.
https://msdn.microsoft.com/en-us/library/office/ff835315.aspx
 
Back
Top