Need delay before new sub executes

artz

Well-known Member
Joined
Aug 11, 2002
Messages
830
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a sub in a workbook that performs a web query and places data into columns on a worksheet. (stock market data)

Some of the data are subsequently used to perform calculations in other columns on the same worksheet.

Before End Sub in the web query sub, I call another sub to place some of the downloaded data from the web query and some of the calculations performed on this data into a different worksheet in the same workbook.

The problem is that the calculations do not finish before the call to the new sub is done causing missing data on the new worksheet , resulting in cells with N/A or DIV/0, etc.

I tried to insert a delay into the first sub and it did just that; simply paused for the old sub for the amount of time specified, it did not just delay the call to the new sub.

Seems that there must be a way to say "if worksheet calculations complete, then call New sub()" from the old sub. (old sub is initiated by a CommandButton click) I want the new sub to also be initiated by the same CommandButton click, but after the calculations initiated by old sub are complete. Make sense?

Does anyone in the Forum have a suggestion on how to do this?

Thanks,

Art
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Thanks for your suggestion that is what I tried. The whole sub kind of hangs, then the new sub runs. It wasn't the way I wanted the subs to run to run execution-wise. -Art
 
Upvote 0
Try

Code:
Do Until Application.CalculationState = xlDone
    DoEvents
Loop
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

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