about Application.ScreenUpdating logic

Copper Contributor

qazzzlyt_0-1675176208660.png

So I assume you are familiar with this classical code above. I have 2 questions:

 

(1) It seems, even without the last ScreenUpdating=True, when VBA end, screen will update anyway? So is this line really necessary? (assume this is the last sub, no other sub/function is running after it)

 

(2) Sometimes, my code stop before ScreenUpdating=True is executed, because there is an unexpected error in main code, or I stop it intentionally.

In some cases, my excel will freeze after VBA is stopped early, I have to trigger a ScreenUpdating=True some where to fix it; however, in other cases, excel screen updates normally. Any one have same experience? What is causing the inconsistent outcome here?

 

Thank you very much

1 Reply

@qazzzlyt 

I don't know the cause of this behavior, nor Microsoft's official stance on it.

In my experience ScreenUpdating usually resets itself to True even if the code doesn't explicitly do so, but like you I have encountered situations in which the Excel windows wasn't updated. So it's best to include Application.ScreenUpdating = True, and to use an error handler to ensure that this line will always be executed.