Pause loop to give excel time to calculate

Carbuyer0002

New Member
Joined
Apr 23, 2018
Messages
2
Hi all,

From reading through this site, I've written a macro to copy an input from a list, paste it into a model that calculates based on data pulled in from an external source, and then paste specials the results back to the list. However-- when I run it, the macro runs faster than excel can pull in the external data so the pasted results are all inaccurate. I think what it needs is a way to pause the macro to give excel time to catch up before continuing, and from reading other posts maybe something this is the ticket:

" Application.OnTime Now + TimeValue("00:00:10") "

But it's not working. I don't think I am nesting it the right way. Any help would be greatly appreciated! See Below:

Sub Macro3()
'
Dim i As Integer
For i = 1 To 100
Range("A" & i).Select
Selection.Copy
Range("F1").Select
ActiveSheet.Paste
Application.OnTime Now + TimeValue("00:00:10")
Range("G1:H1").Select
Application.CutCopyMode = False
Selection.Copy
Range("B" & i).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A" & i + 1).Select
Application.CutCopyMode = False
Selection.Copy
Range("F1").Select
ActiveSheet.Paste
Application.OnTime Now + TimeValue("00:00:10")
Range("G1:H1").Select
Application.CutCopyMode = False
Selection.Copy
Range("B" & i + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Next i

End Sub
 

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
I use for delay=1 to 1000000000:next delay

if necessary put for delay2=1 to 50:next delay2 in front

then you can change the 50 up or down
 
Upvote 0
Thank you, "for delay..." makes the code pause like you said. However the pasted results are still incorrect. I must have an error somewhere else in the code. Any ideas?
 
Upvote 0
extract one piece of data manually from your source, compare how you did it with your code. I have no experience of pulling data from websites.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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