Refresh Excel Pivot Table Automatically
When you update a pivot table’s source data in Excel, the pivot table does not update automatically. You can set the pivot table to update when the Excel file opens, but that doesn’t help if you’re making changes after the file opens.
If you can use macros in your Excel file, you can use an event procedure to automatically update the pivot table if the source data
changes.
Add the Event Procedure Code
In this example, the source data is on a sheet named "Forecast", and the pivot table is on the "Product" sheet. To add the event code, follow these steps:
Right-click on the the sheet tab for the Forecast sheet, and click View Code

Copy the following code to the Forecast worksheet module
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheets("Product").PivotTables(1).PivotCache.Refresh
End Sub
The worksheet module in your workbook might not have Option Explicit at the top. You can type that line in, if it's missing.

Unprotect the Worksheet
If the pivot table worksheet is protected, you can add code to unprotect it, and then protect it again.
Private Sub Worksheet_Change(ByVal Target As Range)
With Worksheets("Product")
.Unprotect Password:="yourpassword"
.PivotTables(1).PivotCache.Refresh
.Protect Password:="yourpassword"
End With
End Sub
Test the Refresh Code
To test the pivot table refresh code, make a change to the data on the Forecast sheet.
- Making the change will trigger the Forecast sheet’s Change event.
- In the Event code, the pivot cache for the Product sheet’s pivot table is refreshed.
More Information
- Create a Pivot Table in Excel 2007
- Excel Pivot Table -- Dynamic Data Source
- Automatically Include New Data in a Pivot Table
___________________






Nice article, Debra!
Some notes:
1) If your PT is on a separate worksheet from your source data (which is what I do nearly all the time), the SheetActivate event for the worksheet holding the PT might be the better place to hold the refresh code. That way, if I make multiple updates in the source data, I don’t get multiple refreshes; rather, I just get the one refresh when I actually visit that PT again.
2) I also like using the workbook events rather than the sheet events. That way, if my workbook contains multiple PTs, one event sub at the workbook level can manage updates for all PTs in the workbook
3) Refreshing the PT is a must, but we also need to make sure we keep up with changes in the size of the source range for the PT. I typically do that with dynamic named ranges in Excel 2003 or earlier, or Tables in Excel 2007/2010.
Last year I wrote an article ; I’d love to get your feedback on it.
Cheers,
Patrick
great job!
Excellent. This is just what a was looking for: a live update mechanism for a Pivot Table.
I appreciate it.