Make VB wait for excel to calculate a sheet before carrying on

ZainE

New Member
Joined
Feb 11, 2011
Messages
13
Hi

I'm using Excel 2007 and Windows XP Pro...

I'm trying to get VB to wait for excel to calculate a sheet before carrying on with the rest of the macro.

Code:
            Application.Calculation = xlCalculationManual
 
            Application.Calculate
            While Application.CalculationState <> xlDone
                'MsgBox Application.CalculationState
                DoEvents
            Wend

The above seems to work but I don't want to calculate the entire workbook (which is what
Code:
Application.Calculate
does). I would prefer to use something like
Code:
Sheets("Sheet1").Calculate
instead.

But when I do that, the Application.CalculationState doesn't work i.e. Application.CalculationState is always not equal to xldone.

Can you help?
Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I think if only one Sheet is recalculated, Application.CalculationState will not be xlDone.

Please see http://www.decisionmodels.com/calcsecretsf.htm

You can:
ReCalculate the whole workbook in the while loop. Or
Change calculation to auto at the end of the macro. (fastest)
 
Upvote 0
Thanks drsarao.

I think I am calculating the whole workbook (i.e. Application.Calculate) currently...

For your second option, are you suggesting something like the following?

Code:
            Application.Calculation = xlCalculationManual
            
            
Begin loop
 
           'Do some stuff

            Application.Calculate
            While Application.CalculationState <> xlDone
                 DoEvents
            Wend
 
            'Do some more stuff
End loop
 
Application.Calculation = xlCalculationAuto
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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