On Error Goto 0 not resetting error trapping
15,268
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.
Author by
whytheq
Current addictions: DAX / POWERSHELL Time served with: (T-)sql / MDX / VBA / SSRS Would like more time for the following: C# Python Maxim: if you build something idiot-proof, the world will build a better idiot
Updated on July 26, 2022Comments
-
whytheq almost 2 years
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
-
whytheq about 11 yearslol - this link is spot-on - really seems like my question is a duplicate - I've voted to close it with a reference to your other answer
-
AjV Jsy almost 9 years
Err.Clear
doesn't seem to allow another error handler to be set up. I only get the required results (skipping a few lines of code if there's an error, and then doing something similar again) withOn Error GoTo -1
before setting anotherOn Error...
- see example here stackoverflow.com/questions/11998836/…