PowerQuery Macro Refresh

tcardwell

Board Regular
Joined
Dec 22, 2013
Messages
86
Hello,

Trying to get an automatic refresh of tables and pivot table with the following macro:

Sub Refresh()
'
' Refresh Macro
'
ActiveWorkbook.Connections("Power Query - Jan2008").Refresh
ActiveWorkbook.Connections("Power Query - Feb2008").Refresh
ActiveWorkbook.Connections("Power Query - Mar2008").Refresh
ActiveWorkbook.Connections("Power Query - Transactions").Refresh
Worksheets("Transactions").PivotTables("PivotTable1").PivotCache.Refresh
End Sub

What ends up happening is that the Refresh button(that contains the macro) has to be pushed twice in order for the pivot table to refresh. Ideal behaviour is to only have to click the Refresh button once for tables and pivot table to refresh.

Any ideas on how above can be tweaked to accomplish a one click refresh?

Thanks, Tom C
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Using RefreshAll with the Activesheet command generates an error, so I used it with ActiveWorkbook and it does not generate an error. However, original issue does not resolve, still need to click Refresh command twice in order for pivot table to update.
 
Upvote 0
The pivot table should refresh on refresh all

try to un-tick this:

ntinRIB.png
 
Upvote 0
That worked!
I also modified the macro to just read:
ActiveWorkbook.RefreshAll

I assume the query dependency info is used to make sure all source data is loaded and refreshed before the last update to the pivot table is made?
 
Upvote 0
Yes, Disable Background Refresh will pause all other operations until the query is done refreshing.
It is highly recommended to turn it off if you 're refreshing queries with VBA.
If you have it on and your code relies on the output of the query then your code jumps to the next step without waiting
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,597
Members
449,174
Latest member
chandan4057

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