RefreshAll in a particular order

BakerUK

New Member
Joined
Nov 19, 2015
Messages
28
Hi all

I have some jobs to run in VB which include tables (updating from external sources) and pivot tables (which link to those tables).

I started with ActiveWorkbook.RefreshAll and it wasn't always updating the pivots, so I changed it to refresh just the table and then the pivots. In some cases that still didn't work, so I added a 5 second delay before the second refresh. In one case that didn't even work!

I've now split out every pivot table to refresh one by one, rather than RefreshAll but it seems very long-winded (I have loads of pivots).

Is there an easier way of writing that?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this:

Code:
For Each sh In ThisWorkbook.Sheets
    For Each pt In sh.PivotTables
        pt.PivotCache.Refresh
    Next
Next
 
Upvote 0
Hi, here is another option that you can try that, hopefully, also takes care of refreshing the external data sources:

Code:
Sub RefreshEmAll()
Dim cn As WorkbookConnection, pc  As PivotCache
For Each cn In ThisWorkbook.Connections
    cn.ODBCConnection.BackgroundQuery = False
    cn.Refresh
Next cn
For Each pc In ThisWorkbook.PivotCaches
    pc.Refresh
Next pc
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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