Calculations off while Form is showing

MarkBoy

Board Regular
Joined
Aug 18, 2004
Messages
110
Hi,

I have a fairly sizable spreadsheet, and the whole thing grinds to a halt if calculations are on while forms are running. As such, I want to turn the calculations to manual while the forms are active, but turn them back to automatic when the form is closed.

Now, obviously:

Private Sub UserForm_Activate()
Application.Calculation = xlManual
End Sub

does the job of switching it to Manual, and the spreadsheet runs like a dream. The problem, however, is that the form is always closed by clicking the top-right-hand "X". And that would seem to NOT activate the following code:

Private Sub UserForm_Deactivate()
Application.Calculation = xlAutomatic
End Sub

Is there any way to trigger a command on a form being closed like that? Any other suggestions of devious ways of dealing with this that I haven't thought of?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You could use the Userform_Terminate event.
 
Upvote 0
Thanks! For some reason, my searching never turned up that event!

That has sped up my spreadsheet dramatically (like a previously 20sec subroutine is now instanteous), now I just have to figure out a way to make it faster when calculations are actually active!
 
Upvote 0
Ok, have encountered my next difficulty. All my searching has said that the Userform_Activate event should occur every time a form gains focus. Each of my forms calls other forms, and now each of them switches calculation to Manual on activation and switches calculation to Automatic on termination.

The problem is that when I close one form, and go back to the one I was previously using, calculation is definitely back to Automatic. I'm resigned to the fact that it will recalculate when shifting between forms, but it is a huge pain if it continues to calculate while using the first form.

Any suggestions about how this might be made to work?
 
Upvote 0
Use the Userform_Click event so when focus goes back to a userform calculations are switched off?

Isn't one of the Userforms the 'master' form from where the user navigates to all other userforms? If so, you could use that _Terminate event only to switch back on the calculations.
 
Upvote 0
How are you switching from form to form (switching back and forth between two forms can be problematic, particularly if you use the Userform1.show syntax and Unload Me statements in the forms. I agree with Stefan that your simplest bet would be to have a master form if possible (like a switchboard) and have that turn calculation off when loaded.
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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