Delaying VBA processing to allow xls to catch up

RafFiniert

New Member
Joined
Mar 18, 2025
Messages
7
Office Version
  1. 2013
Platform
  1. Windows
I'm happy to read the answer somewhere else if this has already been answered. However, so far, I've been unable to find it.

Problem:
VBA's speed of processing can outstrip the pace of xls processing, necessitating some method of delay in the VBA code

Conventional wisdom:
Set these...

Application.DisplayAlerts = False
Application.DisplayStatusBar = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual

Then manually recalculate sheets as needed.

If the VBA code is still proceeding before the manual recalculations complete, use Wait, Delay, or Loop to force a delay.

I have tried these with varying degrees of success. What bothers me is that waiting for a definitive period of time seems so inefficient--since you have to account for a worst-case scenario. (And the worst-case scenario might vary widely--especially if you're waiting for something to return from a webservice call, which also introduces the speed of your internet connection as a variable.)

It seems like there should be something that says to "wait until processing complete." So far, I haven't found it.

The only thing I have found that works is to do the manual recalculations and then ThisWorkbook.Save (and, yes, I understand that if Application.CalculateBeforeSave is set to True, the manual recalculations are redundant). It seems that the VBA code won't proceed until the save step is complete.

Is there a more elegant solution?
 
Maybe...

VBA Code:
Application.Calculate
Do Until Application.CalculationState = xlDone
   DoEvents
Loop
 
Upvote 0
Solution
Mark that gives me an idea for one of my VBA projects. I've got a spreadsheet containing some VLOOKUP formulas and it makes some calculations based on the values that it returns.

Will the IF statement also work?
VBA Code:
Application.Calculate
If Application.CalculationState = xlDone, Then
do some stuff
 
Upvote 0
If Application.CalculationState= xlDone, Then

Yes it would work if using it as a Boolean test, but no comma in the line and you should tell it what not to do if it is still calculating or pending
 
Upvote 0
Yes it would work if using it as a Boolean test, but no comma in the line and you should tell it what not to do if it is still calculating or pending

ah yes. How would I tell it to WAIT until it's done finishing?
 
Upvote 0
You wouldn't with a Boolean test, it just tells you it has either finished or not. The code in Post 2 won't move on until calculations are done.
 
Upvote 0
Thanks, Mark. That made a measurable (and real) difference. I have 17 uses cases that I'm using for regression testing of what I'm developing. The greatest reduction in processing time was 82%; the least was 42%; average was 52%.
 
Upvote 0

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