Wait for WorkSheet.Calculate to finish

KBARAD

New Member
Joined
Mar 31, 2020
Messages
9
Office Version
  1. 2013
Platform
  1. Windows
I have a (large) worksheet with many interdependencies. Due to the heavy processing demand I've had to take a few measures:
  1. automatic calculation -> manual
  2. do not recalculate on save
  3. a control panel of buttons to selectively recalculate different sheets to allow minimum recalculation depending on which part of the workbooks we want to update
I'm having problems with number 3: It is not feasible to use a full workbook recalculation - It does need to be done sheet by sheet and there are specific sequences to manage. Making vba to control the sequence is fine except for one issue:
WorkSheet.Calculate is non blocking.

I have taken the usual approach of a wait function after doing a sheet.calculate :

VBA Code:
Private Sub waitforcalc()
    Do Until Application.CalculationState = xlDone
        DoEvents 'let events happen, like calculation
    Loop
End Sub

Unfortunately this never leaves the loop: it seems that as long as any cell is still considered "dirty" the CalculationState remains 2 (pending) so this doesn't work for sheet by sheet (and I understand for large books the management of clean/dirty is suboptimal). I have tried the alternative:

VBA Code:
Private Sub waitforcalc()
    Do While Application.CalculationState = xlCalculating
        DoEvents 'let events happen, like calculation
    Loop
End Sub

but this doesn't seem to be waiting.

Is there a way for a large workbook to do sheet based calculation in a blocking call / with a wait phase?
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Watch MrExcel Video

Forum statistics

Threads
1,122,530
Messages
5,596,699
Members
414,088
Latest member
rodriboraun

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
Top