Pivot Table Cache clear

DRANDON

Active Member
Joined
Jun 30, 2006
Messages
268
I have a code snipit to clear my PT Cache prior to entering a new data set.

Sub Clean_Pivots()
For Each pt In ActiveSheet.PivotTables
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next
End Sub

Will any harm come to me if I have this code in upon worksheet.activate event rather than maybe having a button to execute the code only when I need to?

Thanks.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I have a code snipit to clear my PT Cache prior to entering a new data set.

Sub Clean_Pivots()
For Each pt In ActiveSheet.PivotTables
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next
End Sub

Will any harm come to me if I have this code in upon worksheet.activate event rather than maybe having a button to execute the code only when I need to?
No. (You might want an extra step between 'pt.pivotcache.etc' & 'next': pt.pivotcache.refresh)
 
Upvote 0
Thank you. I elected to put all the refresh code in a module and invoke it with a control button. Looks like this
Sheets("TOP 10 IP OP GRAPH").Activate
ActiveSheet.Unprotect
ActiveSheet.PivotTables("pivottable1").PivotCache.MissingItemsLimit = xlMissingItemsNone
ActiveSheet.PivotCache("pivottable1").Refresh
ActiveSheet.PivotTables("pivottable1").RefreshTable
I have 15 sheets with about 20 pivit tables altogether.
Thanks for your reply.
 
Upvote 0
OK. To update all in the one workbook, see code below. Note it is best to not activate objects unless necessary.

Also note I have ignored any need to unprotect/protect sheets. If you have sheet protection, please adjust to suit.

Code:
Sub All()

  Dim wks As Worksheet
  Dim pt As PivotTable

  For Each wks In Worksheets
    For Each pt In wks.PivotTables
      With pt.PivotCache
        .MissingItemsLimit = xlMissingItemsNone
        .Refresh
      End With
    Next pt
  Next wks

  Set pt = Nothing
  Set wks = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

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