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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,216,072
Messages
6,128,631
Members
449,460
Latest member
jgharbawi

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