Karen Schaefer
asked on
VBA code to automatically refresh Pivot tables and slicers at the worksheet level
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?
K
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?
K
Sub Reset()
Dim pt As PivotTable
Application.ScreenUpdating = False
RefreshSlicersOnWorksheet ActiveSheet
For Each pt In ActiveSheet.PivotTables
pt.RefreshTable
Next pt
If MsgBox("Do you want to refresh the PowerPivot Model?", vbYesNo) = vbYes Then
ActiveWorkbook.Model.Refresh
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
sc.ClearManualFilter
Exit For 'unnecessary to check the other slicers of the slicer cache
End If
Next slice
Next sc
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the assist
ASKER
thanks
Pleased that you got it working
ASKER