I have a workbook that has a number of PivotTables spread across a number of worksheets. There's a bunch of slicers on one of the worksheets, and they're pretty slow to load after changing filters/selections. My idea was to remove the Pivot Tables that aren't in the same worksheet as the slicers from the slicers when that worksheet is activated, and add them back again when the worksheet is deactivated, to improve performance. I've written some code to do this, but it's prohibitively slow at the moment - it takes about a minute to run, and the improvement in slicer performance it affords is only something like 1 second instead of 4 seconds. Is there any way to speed up what I've got? TIA!
VBA Code:
Private Sub Worksheet_Deactivate()
'
' OnDeselect Macro
'
'
Application.Calculation = xlManual
Application.ScreenUpdating = False
pts = Array( _
Worksheets("Sheet1").PivotTables("Pivot1"), _
Worksheets("Sheet2").PivotTables("Pivot2"), _
Worksheets("Sheet3").PivotTables("Pivot3"), _
Worksheets("Sheet3").PivotTables("Pivot4"), _
Worksheets("Sheet3").PivotTables("Pivot5"), _
Worksheets("Sheet3").PivotTables("Pivot6"), _
Worksheets("Sheet3").PivotTables("Pivot7"), _
Worksheets("Sheet4").PivotTables("Pivot8"), _
Worksheets("Sheet5").PivotTables("Pivot9"), _
Worksheets("Sheet6").PivotTables("Pivot10"), _
Worksheets("Sheet7").PivotTables("Pivot11"), _
Worksheets("Sheet7").PivotTables("Pivot12"), _
Worksheets("Sheet7").PivotTables("Pivot13"), _
Worksheets("Sheet7").PivotTables("Pivot14"), _
Worksheets("Sheet7").PivotTables("Pivot15") _
)
ss = Array( _
ActiveWorkbook.SlicerCaches("Slicer1"), _
ActiveWorkbook.SlicerCaches("Slicer2"), _
ActiveWorkbook.SlicerCaches("Slicer3"), _
ActiveWorkbook.SlicerCaches("Slicer4") _
)
For Each pt In pts
For Each s In ss
s.PivotTables.RemovePivotTable (pt)
Next s
Next pt
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub