I have a workbook with 20 different pivot tables. Is there any easy way to find all the pivot tables and refresh them in VB?
views:
22632answers:
6
+12
A:
Yes.
ThisWorkbook.RefreshAll
Or, if your Excel version is old enough,
dim w as worksheet, p as pivottable
for each w in thisworkbook.worksheets
for each p in w.pivottables
p.refreshtable
p.update
next
next
GSerg
2008-09-16 10:18:52
+1
A:
You have a PivotTables collection on a the VB Worksheet object. So, a quick loop like this will work:
Sub RefreshPivotTables()
Dim pivotTable As PivotTable
For Each pivotTable In ActiveSheet.PivotTables
pivotTable.RefreshTable
Next
End Sub
Notes from the trenches:
- Remember to unprotect any protected sheets before updating the PivotTable.
- Save often.
- I'll think of more and update in due course... :)
Good luck!
LohanJ
2008-09-16 10:22:35
+5
A:
This VBA code will refresh all pivot tables/charts in the workbook.
Sub RefreshAllPivotTables()
Dim PT As PivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.RefreshTable
Next PT
Next WS
End Sub
Another non-programatic option is:
- Right click on each pivot table
- Select Table options
- Tick the 'Refresh on open' option.
- Click on the OK button
This will refresh the pivot table each time the workbook is opened.
Robert Mearns
2008-09-16 10:37:07
A:
but I need to press it twice to refresh the datasource and then the pivot tables.
piyusha
2010-02-01 06:01:19
A:
Cool solutions!
See more solutions to Pivot Tables in Excel VBA: Refresh Pivot Tables - Atualizando Tabelas Dinâmicas
André Luiz Bernardes A&A - WORK, DON´T PLAY! [email protected]
Twitter: @officespecialis @brzexceldevelop @brzaccessdevel
Andre Luiz Bernardes
2010-05-12 18:34:09