Speeding up add/remove PivotTable to Slicer VBA

bigsim

New Member
Joined
Oct 22, 2008
Messages
7
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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top