Consulting

Results 1 to 5 of 5

Thread: Clear Slicers Using VBA

  1. #1
    VBAX Newbie
    Joined
    Feb 2014
    Location
    Atlanta
    Posts
    5
    Location

    Clear Slicers Using VBA

    I use this code all the time, thanks to one of the forum members!
    Sub SlicerReset()
    
    Dim slcr As SlicerCache
    Application.ScreenUpdating = False
       For Each slcr In ActiveWorkbook.SlicerCaches
        
            slcr.ClearManualFilter
        Next slcr
    Application.ScreenUpdating = True
    
    
    End Sub
    However, I would like to confine it to just the active worksheet or a specific worksheet. Is that possible? Thank you for reading.

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,724
    Location
    Yes and no. If the slicer is linked to tables on another sheet, it will obviously affect those sheets too.

    Try this:
    Sub SlicerReset()
    
        Dim slcr                  As SlicerCache
        Dim slc                   As Slicer
        
        Application.ScreenUpdating = False
        
        For Each slcr In ActiveWorkbook.SlicerCaches
            For Each slc In slcr.Slicers
                If slc.Shape.Parent Is ActiveSheet Then
                    slcr.ClearManualFilter
                    Exit For
                End If
            Next slc
        Next slcr
        
        Application.ScreenUpdating = True
    
    
    
    
    End Sub
    Be as you wish to seem

  3. #3
    VBAX Newbie
    Joined
    Feb 2014
    Location
    Atlanta
    Posts
    5
    Location
    Quote Originally Posted by Aflatoon View Post
    Yes and no. If the slicer is linked to tables on another sheet, it will obviously affect those sheets too.

    Try this:
    Sub SlicerReset()
    
        Dim slcr                  As SlicerCache
        Dim slc                   As Slicer
        
        Application.ScreenUpdating = False
        
        For Each slcr In ActiveWorkbook.SlicerCaches
            For Each slc In slcr.Slicers
                If slc.Shape.Parent Is ActiveSheet Then
                    slcr.ClearManualFilter
                    Exit For
                End If
            Next slc
        Next slcr
        
        Application.ScreenUpdating = True
    
    
    
    
    End Sub
    Thank you. I am looking forward to giving this a try. When I send my dashboard/workbook to others, I delete the worksheet that is storing the source data to shrink the size of the file. Therefore, the pivot table, charts, etc rely on the pivot cache. Will this code allow me to continue the same practice? Thank you again.

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,724
    Location
    As long as your slicers still work manually when you do that, the code should be fine.
    Be as you wish to seem

  5. #5
    VBAX Newbie
    Joined
    Feb 2014
    Location
    Atlanta
    Posts
    5
    Location
    Thank you! I will try and let you know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •