Help with VBA and external data

ϵpsilon

New Member
Joined
Jun 29, 2012
Messages
3
Hi

I've got some external data in cell M7 and need to copy the values to another cell. I've recorded a macro that refreshes the external data and then copies and pastes the values. When I run the macro it copies and pastes the old values while the external data is refreshing.

The code look like this:

Sub Macro2()
'
' Macro2 Macro
'


'
Application.CutCopyMode = False
ActiveWorkbook.Connections("Connection").Refresh
Range("M7:N7").Select
Selection.Copy
Range("D7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

Can anyone help me with this. I've tried adding Calculate before range select and I also tried application wait but it doesn't fix the problem.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I had this exact same problem and it drove me NUTS!! The problem is that your Macro runs faster than your refresh. I use .WaitHostSettle(1)
That will make you macro slow down for a second and wait for your external data to update. You may need to do this several times.
Good luck!
 
Upvote 0
I had this exact same problem and it drove me NUTS!! The problem is that your Macro runs faster than your refresh. I use .WaitHostSettle(1)
That will make you macro slow down for a second and wait for your external data to update. You may need to do this several times.
Good luck!

Thanks for your help. I will try that. I also found that going to data properties and turning off enable background refresh gives it time to update before copying.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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