VB code to turn off automatic calculations

Cossie

Active Member
Joined
May 6, 2002
Messages
328
i am woking on a userform and need to need to be able to turn the automatic calculation on and off to speed up the data entry part.

Any suggestions please
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,

It is a good idea to determine the calculation setting *before* you change it and then turn it back to its pre-routine state at the end of the code.

Code:
Sub test()
Dim CalcSetting As Integer

With Application
CalcSetting = .Calculation
.Calculation = xlCalculationManual
End With

'
' your code here
'

Application.Calculation = CalcSetting
End Sub

This finds the calc setting, sets it to manual, and returns it at the end of the routine.

HTH,
Jay
 
Upvote 0
Jay Thanks for the assistance but it gives me the error message of

method calculation of object_application failed

Any other suggestions would be greatly apprecaited.

Thanks
 
Upvote 0
Where does it fail? Which line? It is quite strange that it would bomb like that, as this is the basic way to change the calculation setting.

Try removing the 'As Integer' from the CalcSetting declaration. Any success then?
 
Upvote 0
Here's some commands that may help.

First command stops excel from doing autoCalculate... I usually include this in "ON Open Events".

Second command forces the active sheet to be calculated while the AutoCalculate is disabled

Third Command I usually put in "Before Close Event" of the workbooks that I have used the first command on.

Code:
Sub CalcOnDemand()
    ' Set APP to manual Calc Only
     Application.Calculation = xlManual
       

    ' Calculate the Active sheet
    ActiveSheet.Calculate
    
    
    ' Set APP to Automatic calc
     Application.Calculation = xlAutomatic
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,832
Messages
6,127,152
Members
449,366
Latest member
reidel

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