Avatar of Luis Diaz
Luis Diaz
Flag 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.
Microsoft OfficeMicrosoft ExcelVisual Basic ClassicVBA

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Luis Diaz

ASKER
Thank you very much for your feedback.
Should I add those procedures inside modules, Sheets or ThisModules?
Luis Diaz

ASKER
Ok, I added in ThisWorkbook and it works perfectly. Thank you again for your help!
Subodh Tiwari (Neeraj)

You're welcome! Glad it worked as desired.
Thanks for the feedback.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck