Home » excel » excel – VBA Performance, what order should use to disable / enable screen updating

excel – VBA Performance, what order should use to disable / enable screen updating

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a macro in place that toggles the following:

 Application.ScreenUpdating = False
 Application.EnableEvents = False
 Application.DisplayAlerts = False
 Application.Calculation = xlCalculationManual

I turn them all on/off at the same time, but I noticed that sometimes EnableEvents does not turn back on, and screenUpdating does not turn off.

Is there a specific order I should follow because they somehow affect each other when toggling them?

How to&Answers:

Is there a specific order I should follow because they somehow affect each other when toggling them?

No.


Concerning non-toggling off or on, probably somewhere in the code you are having On Error GoTo Somewhere and you are skipping the lines with the toggling? (Just guessing).

Answer:

Rather than setting all of those back to True, which can cause problems for people that have explicitly set calculation to manual, you should record the current settings, before changing anything, and then restore the settings to their original values when you are done. See CodeReview for an example of a class that manages this for you.

The only interaction might come about with Calculation and EnableEvents, but only if there are events configured for worksheet/workbook calculate.