Screenupdating x On Error Goto Errorhandler

Asked

Viewed 114 times

0

With the code below:

Application.ScreenUpdating = False
Application.EnableCancelKey = xlDisabled
On Error GoTo ErrorHandler

'Código

Exit Sub
ErrorHandler:Application.ScreenUpdating = True

'Código caso erro

End Sub

Screenupdating = False coming before On Error Goto Errorhandler in the code, interferes with the On Error application?

  • 1

    An explanation in English that I like very much is of this website. Does not interfere with the application of On Error, just take a test by inserting a split by zero x = 1 / 0. You will see that the On Error is applied correctly. Go through the code step-by-step with the key F8.

  • Very good this site.

1 answer

2

Application.ScreenUpdating = False Disables screen update and always at the end of the code you have to activate Application.ScreenUpdating = True. Does not interfere with On Error GoTo ErrorHandler but Application.ScreenUpdating = True that is after, will not be executed if there is no error. You can do the following:

Application.ScreenUpdating = False
Application.EnableCancelKey = xlDisabled
On Error GoTo ErrorHandler

'Código
fin:
   Application.ScreenUpdating = True
Exit Sub

ErrorHandler:

'Código caso erro

GoTo fin

So, even if there is no error or if there is an error, it will activate the screen update before you finish Exit Sub

  • Or instead of making one fin: and GoTo, insert the finalisation codes into ErrorHandler:

  • 1

    But if no error will not run Application.ScreenUpdating = True. The execution will not come in Errorhandler.

  • 1

    True, it’s just that I use ErrHandler: otherwise, there uses a If Err.Number <> 0 Then. But this way it works, I was just giving another suggestion of how to perform. Or you create a function to treat each type of error.

  • Good afternoon everyone! Even reversing the order between the two lines of code, the problem continues. In my case, this is when I use Listobjects to access Tables. If I don’t want to change the name of the spreadsheet or table, the macro stops in the traditional error, when for me should fall in Onerror. I will close the thread and open a more specific one.

  • There is another problem. You can change this post with another title and the data that contains the error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.