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
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.
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.
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.
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.”
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With