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?
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 = TrueEnd SubPublic 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 IfEnd Sub