Code To Refresh Table

Herbiec09

Active Member
Joined
Aug 29, 2006
Messages
250
Good afternoon All,

I was wondering if someone could assist me with a VBA code which I can embed on to a sheet so that whenever that sheet is opened a power query table that is part of that workbook is refreshed.

Not sure if this is enough detail. If not, please let me know

Many Thanks

Herbz
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi there

Just record a macro doing what you want to do (i.e. refresh the query table), then place that macro in the relevant worksheet vba code area. To get at this, right click the worksheet name and select view code. Copy the macro you recorded to this area and rename it as : Private Sub Worksheet_Activate()
 
Upvote 0
The easiest way would be to refresh everything with
Code:
Activeworkbook.RefreshAll

But if you only want to refresh a certain query the code gets a bit more complex:

https://www.excelguru.ca/blog/2014/10/22/refresh-power-query-with-vba/

The way to get the code to run automatically would be to use the Worksheet.Activate event. However I'd recommend to think twice before using this to refresh the query: It might take some time and if users go back and forth between the sheets it gets annoying to wait every time you go to this sheet. It might be better to add a button and use that to trigger the macro. If the source data isn't likely to change during the workbook is open you could also use the Workbook.Open event.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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