Last active
April 22, 2018 08:42
-
-
Save ateneva/fd3e0580ce6fefc20ca9c2358360e128 to your computer and use it in GitHub Desktop.
How do I refresh all Pivot Tables in my workbook?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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