Skip to content

Instantly share code, notes, and snippets.

@ateneva
Last active April 22, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateneva/fd3e0580ce6fefc20ca9c2358360e128 to your computer and use it in GitHub Desktop.
Save ateneva/fd3e0580ce6fefc20ca9c2358360e128 to your computer and use it in GitHub Desktop.
How do I refresh all Pivot Tables in my workbook?
Sub RefreshPTs()
Dim Wbk As Workbook
Dim Wks As Worksheet
Dim PT As PivotTable
Dim PC As PivotCache
'*****************************
'written by Angelina Teneva
'*****************************
'refresh pivot caches
'useful when you have multiple caches '+ listobjects fed through SQL queries
'and you only want to refresh the pivot tables but not the listobjects
For Each PC In ActiveWorkbook.PivotCaches
PC.Refresh
Next PC
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'refresh all pivot tables in a workbook
For Each Wks In ActiveWorkbook.Worksheets
Wks.Activate
For Each PT In ActiveSheet.PivotTables
PT.RefreshTable
PT.SaveData = True
Next PT
Next Wks
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment