Update PivotChartTable

SerenityNetworks

Board Regular
Joined
Aug 13, 2009
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I'd like to assign a macro to update all the PivotChartTables in a worksheet. I will need to have a loop, but right now I can't even design a macro to update even one chart. When I record a macro to do it, I get:
Sub TestUpdate() ActiveChart.ChartArea.Select ActiveSheet.PivotTables("PivotChartTable8").PivotCache.Refresh ActiveChart.ChartArea.Select ActiveSheet.PivotTables("PivotChartTable9").PivotCache.Refresh End Sub

But when I try to run it, I receive an error on the first refresh line (even if I have the chart already selected). The error is:
Run-time error '1004':
Unable to get the PivotTables property of the Worksheet class

I'm lost on getting the code I need to refresh each chart. Any help will be appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
The following seems to be working. If there are any other suggestions, then please feel free to post them.

VBA Code:
Sub RefreshPivotTableCache()
   Dim PivotCache As PivotCache
   On Error GoTo ErrorHandler
   For Each PivotCache In ActiveWorkbook.PivotCaches
       PivotCache.Refresh
   Next PivotCache
   Exit Sub
ErrorHandler:
 MsgBox ("There was an error in refreshing the charts.  Please refresh each one manually.")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,611
Members
449,109
Latest member
Sebas8956

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