Automatically refresh pivot tables

dlb

New Member
Joined
Apr 10, 2006
Messages
42
I have 2 pivot tables set up on one sheet in a work book the pivot tables are linked to a report that has to have rolling totals and averages. My solution was to create two pivot tables one to calculate the total and one to calculate the average.

I would like to auto refresh both pivot tables by clicking on the worksheet tab. I am able to refresh the top pivot table with this code, is there a way to refresh both pivot table by selecting the tab?

Code:
Private Sub Worksheet_Activate()
PivotTables(2).PivotCache.Refresh
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If these are the only pivot tables then why not try RefreshAll.
 
Upvote 0
Thanks for your help, I have absolutley no skills with code and need to ask for your patience in advance.

I tried changing "Refresh" to "RefreshAll" with no luck, please see below

Code:
Private Sub Worksheet_Activate()
PivotTables(2).PivotCache.RefreshAll
End Sub
 
Upvote 0
RefreshAll applies to the workbook not the specific pivot tables or pivot caches.
Code:
ThisWorkbook.RefreshAll
Note, this will refresh all pivot tables and queries - that's why I asked if you just had the couple of pivot tables you mentioned.

Give RefreshAll a go and if it doesn't work post back.:)
 
Upvote 0
I tried this exactly, with no luck:

ThisWorkbook.RefreshAll

Should I have added more to it?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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