How to Refresh All Pivot Tables with VBA (4 Ways)

This code will refresh all the Pivot Tables of the active workbook.

Dim Table As PivotTable
For Each Table In ActiveWorkbook.PivotTables
    Table.RefreshTable
Next Table

A Pivot Table is a special type of table in an Excel worksheet that contains two categories of data titled Row and Value, respectively. All the columns of the table are categorized under these two categories.

Pivot Table to Refresh All Pivot Tables with VBA in Excel

It’s generated automatically from a data set if you select the data set and go to the PivotTable option in the Insert toolbar.

Pivot Table with Name to Refresh All Pivot Tables with VBA in Excel


Method 1 – Refreshing a Single Pivot Table in Excel

To refresh a single Pivot Table, first, you have to refer to it as a PivotTable object. Then you have to use the RefreshTable method of VBA. We’ve got a Pivot Table called PivotTable1 in the active worksheet.

Pivot Table to Refresh All Pivot Tables with VBA in Excel

  • Use the following lines of code:
Dim Table1 As PivotTable
Set Table1 = ActiveSheet.PivotTables("PivotTable1")
Table1.RefreshTable

  • Run the code, and it’ll refresh the Pivot Table called PivotTable1 in the active worksheet.

Read more: How to Auto Refresh Pivot Table in Excel


Method 2 – Refreshing All Pivot Tables of a Worksheet in Excel

To refresh all the Pivot Tables of the active worksheet, you have to iterate through each Pivot Table of the ActiveSheet.PivotTables object. Then use the RefreshTable method.

Dim Table As PivotTable
For Each Table In ActiveSheet.PivotTables
    Table.RefreshTable
Next Table

VBA Code to Refresh All Pivot Tables with VBA in Excel

Read more: Pivot Table Not Refreshing


Method 3 – Refreshing All of the Pivot Tables of a Workbook in Excel

To refresh all the Pivot Tables of the active workbook, iterate through each table by the ActiveWorkbook.PivotTables object of VBA. Then use the RefreshTable method.

Dim Table As PivotTable
For Each Table In ActiveWorkbook.PivotTables
    Table.RefreshTable
Next Table

Read more: How to Automatically Update a Pivot Table When Source Data Changes


Method 4 – Refreshing the Pivot Table Cache with Excel VBA

To refresh the Pivot Table cache, iterate through each Pivot Table cache of the active workbook by the ActiveWorkbook.PivotCaches object.

Dim Cache As PivotCache
For Each Cache In ActiveWorkbook.PivotCaches
    Cache.Refresh
Next Cache

Read more: How to Auto Refresh Pivot Table without VBA in Excel


Download the Practice Workbook


Further Readings


Get FREE Advanced Excel Exercises with Solutions!
Rifat Hassan
Rifat Hassan

Rifat Hassan, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, has worked with the ExcelDemy project for almost 2 years. Within these 2 years, he has written over 250 articles. He has also conducted a few Boot Camp sessions on effective coding, especially Visual Basic for Applications (VBA). Currently, he is working as a Software Developer to develop and deploy additional add-ins to enhance the customers with a more sophisticated experience with Microsoft Office Suits,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo