Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Error Goto 0 not resetting error trapping

I was under the impression that On Error GoTo 0 reset error handling.

So why does On error resume next not seem to be registering in the following?

Sub GetAction()
Dim WB As Workbook
Set WB = ThisWorkbook

On Error GoTo endbit:
'raise an error
Err.Raise 69
Exit Sub
endbit:
On Error GoTo 0 '<<<reset error handling?

On Error Resume Next
WB.Sheets("x").Columns("D:T").AutoFit
MsgBox "ignored error successfully and resumed next"    

End Sub
like image 314
whytheq Avatar asked Mar 21 '13 08:03

whytheq


People also ask

Does On error GoTo 0 clear the error?

On Error GoTo 0 disables error handling in the current procedure. It doesn't specify line 0 as the start of the error-handling code, even if the procedure contains a line numbered 0.

How Do I Stop On error Resume Next?

Basic Error Handling Overview To shut off (disable) the active handler, use On Error GoTo 0 . Doing so will close off the code block that uses that handler. Alternatively, exit the subroutine using Exit Sub , which automatically turns off the handler.

How do I fix VBA error?

Go to the VBA toolbar and click on Tools and then click on Options. In the Options dialog box, click on the General tab and make sure that within the 'Error Trapping' group, 'Break on Unhandled Errors' is checked.

How do I fix an overflow error in VBA?

The data type Byte can hold values from 0 to 255. So it causes an error. To fix the error, we either change the data type or reduce the value assigned to the variable “Number.”


1 Answers

You need to use On Error GoTo -1 or Err.Clear to reset error trapping.

Check this answer I posted a few months ago for a more detailed explanation.

like image 199
Francis Dean Avatar answered Oct 14 '22 08:10

Francis Dean