Userform: manual calculation mode makes code running very slow. How can I avoid the same speed losss when turning automatic again?

Jamualson

Board Regular
Joined
Feb 17, 2021
Messages
145
Office Version
  1. 2019
Platform
  1. Windows
I have a subrutine which runs when a button is pressed on a userform. However it was very slow - 5-10 sec. Then I turned off calculation mode (manual) and speed became much better (0.5-1 sec)

However, when at the end of the sub I activate again the automatic calculation mode --> it takes 3-4 secs and until the calculation is finished I can not interact with the userform.

How could I improve this? I am thinking about turning back automatic calculation mode not at the end of the sub, but when the userform is quitted. So until that - no matter how many times my sub runs - it will be fast. How is this idea? Is it has down sides?

And if this is a good idea, how could I run the Application.Calculation = xlCalculationManual command when userform is about to be closed?
I did not find any example how to attach this to the close of a userform.

Thank you very much for your idea, have a nice day
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
in the form terminate event:
dbl-click the form
select the terminate event, (right event combo box)

Code:
Private Sub UserForm_Terminate()
Application.Calculation = xlCalculationManual
End Sub
 
Upvote 0
Solution
in the form terminate event:
dbl-click the form
select the terminate event, (right event combo box)

Code:
Private Sub UserForm_Terminate()
Application.Calculation = xlCalculationManual
End Sub
Thank you very much
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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