Link to home
Create AccountLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

VBA Excel: Refresh pivot tables & tables automatically

Hello experts, I have the following procedure which allows me to refresh the various pivot tables I would like to add some enhancements:


Sub Refresh_Pivot()
Dim PT As pivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.PivotCache.Refresh
Next PT
Next WS
End Sub

Open in new window


1.      Run the procedure after I change a data or after a save
2.      Include in the procedure the refresh of the various tables in the workbook

Thank you very much for your help.
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Luis Diaz

ASKER

Thank you very much for your feedback.
Should I add those procedures inside modules, Sheets or ThisModules?
Ok, I added in ThisWorkbook and it works perfectly. Thank you again for your help!
You're welcome! Glad it worked as desired.
Thanks for the feedback.