Auto-refresh Pivot Tables when souce data changes

glee0511

New Member
Joined
Aug 28, 2013
Messages
11
Hi there,

I'd like to know how to have a pivot table automatically refresh itself as soon as data is changed in the source table. My source data and pivot table are on the same workbook, and I have 2 pivot tables(in different sheets) with same source data (in another sheet).

Thanks in advance.. :-)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Thank you, but what I need is the auto-refresh. I have seen some steps on the other forum but it seems details are incomplete.
 
Upvote 0
Hi,

Since your PivotTable's are stored in separate worksheets from the source data, another (less expensive) option might be to refresh the PivotTables when you activate any of the PivotTable worksheets. One way to do this might be as follows:

In a regular module enter the following:

Code:
Sub ptRefresh()


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


End Sub

Assume Sheet2 and Sheet3 contain the PivotTables. In each of the associated Worksheet modules enter:

Code:
Private Sub Worksheet_Activate()
    Call ptRefresh
End Sub

If you really want them to refresh as soon as the data changes (although I don't think it's a good idea), you can apply the same procedure, but using the Worksheet_Change event in the Sheet1 (source data) worksheet module, something like this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Call ptRefresh
End Sub
If you do actually use this, you should add further restrictions as required depending on the setup of your source data so only changes in that particular region of the worksheet activate the refresh procedure.

For more on the distinction between regular and worksheet modules see:
Excel VBA -- Adding Code to Excel Workbook

For other PivotTable refresh options see:
Refresh Pivot Table via VBA. Update Pivot Table With VBA
MS Excel: Automatically refresh pivot table when data in a sheet changes in Excel 2003/XP/2000/97
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top