Take the 2-minute tour ×

Can anyone find the difference between 'On error goto -1' and 'on error goto 0' in VBA? I've tried google and msdn, but I've had no luck.

share|improve this question
This documentation is for Visual Basic, not VBA, but the concepts are similar enough in this case that it should explain the difference. –  vcsjones Jan 4 '13 at 14:30

2 Answers 2

up vote 18 down vote accepted

On Error GoTo 0 disables any error trapping currently present in the procedure.

On Error GoTo -1 clears the error handling and sets it to nothing which allows you to create another error trap.

Example: On Error GoTo -1

After the first error is raised, it will GoTo ErrorFound which will then clear the routine's error handling and set a new one, which will GoTo AnotherErrorFound when an error is found.

Sub OnErrorGotoMinusOneTest()

    On Error GoTo ErrorFound

    Err.Raise Number:=9999, Description:="Forced Error"

    Exit Sub


    On Error GoTo -1 'Clear the current error handling
    On Error GoTo AnotherErrorFound 'Set a new one
    Err.Raise Number:=10000, Description:="Another Forced Error"


    'Code here

End Sub

Example: On Error GoTo 0

After the first error is raised, you will receive the error as error handling has been disabled.

Sub OnErrorGotoZeroTest()

    On Error GoTo 0


End Sub
share|improve this answer
+1, good explanation. It is interesting to point out that ONLY On Error Goto -1 will allow further error trapping within error trapping. Infact, even On Error Resume Next will still result in an untrapped error that halts operation. –  Daniel Cook Jan 4 '13 at 15:32
Thank you both so much, @Francis Dean and Daniel Cook. I've ended up using this in my code a long time ago, but never knew why I could get it to work after Goto -1. –  sterlingalston Jan 4 '13 at 17:27
Interesting, thanks for the explanation. Is there any difference between On Error Goto -1 and Err.Clear? –  Peter Albert Jan 4 '13 at 18:36
Sorry for the overdue reply, there is no difference between Err.Clear and On Error GoTo -1 in that they both clear the current routine's error handler. –  Francis Dean Jan 10 '13 at 11:42

Here's another one


Shows a bit more on what's the difference between GoTo 0 and GoTo -1

share|improve this answer

Your Answer


