Archive

Archive for January, 2011

Are you a big fan of pivot tables?

I use pivot tables constantly for data mining.  When becoming comfortable with them, they become very powerful.  I’m not going to get into the detail of how to set them up or what they are used for, you are definitely my target market if you use them.  I’ve had Excel files before that have multiple pivot tables across many tabs.  This piece of VBA code gives you confidence that all pivot tables are refreshed, as this code will go through each pivot table on each tab and refresh accordingly.  This doesn’t take a lot of code, but is very easy to add to your personal workbook (see here).    Here you go…

Sub RefreshAllPivots()
‘Dim is creating the shortcuts for Worksheet and Pivot Table
Dim wks As Worksheet
Dim pt As PivotTable

For Each wks In Worksheets
‘Cycles through each worksheet

For Each pt In wks.PivotTables
‘Cycles through each pivot table

pt.RefreshTable
‘Refreshes the pivot table

Next pt
‘Skips to the next pivot table and refreshes until no more pivots to refresh on that worksheet
Next wks
‘Goes to the next worksheet and starts refreshing until all tabs have been seached and updated

End Sub

Hope this helps!

Categories: Macros, Pivot Tables Tags: ,
Design a site like this with WordPress.com
Get started