troubleshooting Question

VBA code to automatically refresh Pivot tables and slicers at the worksheet level

Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America asked on
VBAMicrosoft Excel
5 Comments1 Solution3209 ViewsLast Modified:
I have found various versions of code to refresh Pivot tables, Update Data Models and refresh slicers.  However, I am having an issue with some of the code for clearing the Slicers to reset them back to display all options.

Debug error on "sc.ClearManualFilter"

Can someone point me to the best option for resetting the Pivot tables, slicers and refreshing the underlying Data Model from the Power Query/Pivot?

Sub Reset()
Dim pt As PivotTable
 Application.ScreenUpdating = False
 RefreshSlicersOnWorksheet ActiveSheet
    For Each pt In ActiveSheet.PivotTables
    Next pt
     If MsgBox("Do you want to refresh the PowerPivot Model?", vbYesNo) = vbYes Then
    End If

     Application.ScreenUpdating = True
End Sub

Public Sub RefreshSlicersOnWorksheet(ws As Worksheet)
    Dim sc As SlicerCache
    Dim scs As SlicerCaches
    Dim slice As Slicer

    Set scs = ws.Parent.SlicerCaches

    If Not scs Is Nothing Then
        For Each sc In scs
            For Each slice In sc.Slicers
                If slice.Shape.Parent Is ws Then
                    Exit For 'unnecessary to check the other slicers of the slicer cache
                End If
            Next slice
        Next sc
    End If

End Sub
Roy Cox
Group Finance Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros