Excel VBA On Error GoTo Next: What It Really Does

VBA & macros · Updated November 19, 2026

Excel VBA does not have an On Error GoTo Next statement. The syntax people usually mean is On Error Resume Next: it tells VBA to continue with the statement immediately after a runtime error, rather than stop and display an error dialog. Use it only around a specific operation you expect might fail, then check the error and turn that behavior off.

What “On Error GoTo Next” means

VBA provides several forms of the On Error statement, but “GoTo Next” is not one of them. The likely source of the mix-up is the difference between two valid forms: On Error Resume Next and On Error GoTo label. The first resumes execution after an error; the second transfers execution to a named error-handling section in the procedure.

“Next” in On Error Resume Next means the next executable statement after the one that failed. It does not mean “skip to the next loop iteration,” nor does it mean “keep going until the macro finishes safely.” Those distinctions matter: the next statement might rely on the result of the failed operation, so continuing blindly can produce incorrect output or further errors.

How On Error Resume Next works

When an error occurs while this mode is active, VBA suppresses the usual break and continues at the following statement. The error is still recorded in the built-in Err object. Its Number property identifies the error, and Description provides a message. Your code must inspect those properties if it needs to know whether the operation worked.

For example, a line that tries to refer to a worksheet that is not in the workbook can raise an error. With On Error Resume Next active, VBA moves on instead of stopping. If the next line assumes the worksheet reference is valid, the macro may then act on an empty object variable or fail later in a less obvious place. Continuing is not the same as fixing the error.

The setting applies within the current procedure, not just to one line. It remains in effect until the procedure ends or you change the error-handling mode. That is why a short, clearly bounded section is safer than placing On Error Resume Next at the top of a long macro.

A careful example: checking for an optional worksheet

This example checks whether the current workbook contains a sheet named Archive. The lookup is the one operation expected to fail if that sheet is absent. Before running any macro, save a copy of the workbook: VBA macros cannot be undone with Ctrl+Z. In the Excel desktop app for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11, insert the procedure in a standard module, and run it from the editor or Excel’s macro controls.

Sub CheckArchiveSheet()
    Dim ws As Worksheet
    Dim errorNumber As Long
    Dim errorDescription As String

    ' Check a copy of the workbook before running macros.
    On Error Resume Next
    Set ws = ThisWorkbook.Worksheets("Archive")
    errorNumber = Err.Number
    errorDescription = Err.Description
    Err.Clear
    On Error GoTo 0

    If errorNumber <> 0 Then
        MsgBox "Archive sheet was not found: " & errorDescription, vbExclamation
        Exit Sub
    End If

    MsgBox "The Archive sheet exists."
End Sub

The macro copies the error details into variables immediately after the lookup. It then clears the error information and uses On Error GoTo 0 to stop suppressing errors. The later test uses the saved error number, so clearing Err does not erase the result the macro needs. If the lookup succeeded, ws refers to the sheet; if not, the macro reports the problem and exits.

This pattern is appropriate when absence is an expected possibility and the code has a deliberate response. It is not a reason to ignore every error from a larger block. If another line were accidentally added between the lookup and the error check, that line could fail too, making it harder to identify which operation caused the problem.

When to use it—and when not to

Use On Error Resume Next for a narrow operation whose failure is anticipated and whose outcome you will check. Common cases include looking for an optional worksheet, attempting to access an optional object, or handling a cleanup action that may legitimately have nothing to clean up. In each case, decide what the macro should do when the operation fails before suppressing the error.

  • Reasonable use: Try to find a named sheet, check Err.Number, and either use the sheet or report that it is missing.
  • Risky use: Put it at the beginning of a large procedure and let every later error pass silently.
  • Not a substitute for validation: Check inputs and workbook assumptions directly where possible instead of using an error as the normal way to detect every condition.
  • Not a repair: Suppressing an error does not make a failed assignment or calculation succeed.

In a loop, be especially clear about what “next” means. If an individual row may be invalid, handle that row deliberately and continue the loop using ordinary control flow, such as an If test. On Error Resume Next itself continues with the next statement in the same procedure; it does not automatically skip to the next row. A broad suppression setting inside a loop can conceal a problem on every iteration.

How it compares with a GoTo error handler

A conventional handler is usually preferable when errors should be reported, logged, or followed by cleanup. With On Error GoTo Handler, an error transfers control to a label in the same procedure. The handler can record the error, close or restore resources as appropriate, and exit in a controlled way. The label must exist in that procedure; it is not a reference to another procedure or a promise to go to the next line.

By contrast, On Error Resume Next leaves the normal sequence of statements in place and suppresses the immediate interruption. It can be concise for one expected failure, but it provides no automatic diagnosis or recovery. A handler is more explicit for unexpected errors, while local resume-next handling is useful for a small, anticipated check. A procedure may use both approaches in separate sections, but keep the scopes and transitions easy to follow.

On Error GoTo 0 disables an enabled error handler in the current procedure and restores normal error behavior. It is often used after a short resume-next section so later code will not inherit silent error suppression. VBA also has On Error GoTo -1, which clears the current procedure’s error state; it is not the same as jumping to a label named minus one. Most readers starting with a small optional lookup can use Err.Clear and On Error GoTo 0 without needing that less common form.

Common mistakes and how to avoid them

  • Writing invalid syntax: On Error GoTo Next is not a valid way to skip an error. Use On Error Resume Next for that behavior, or use a real label with On Error GoTo.
  • Forgetting to check Err: A macro can appear to finish normally while an important operation failed. Check Err.Number immediately after the risky statement and take a meaningful action.
  • Leaving suppression active: Use On Error GoTo 0 as soon as the narrow risky section is over. Otherwise, unrelated problems later in the same procedure may also be hidden.
  • Checking the wrong error: Another failing statement can replace the information you intended to inspect. Capture the number and description directly after the operation you are testing.
  • Assuming Err clears itself: Do not rely on a successful later statement to erase the earlier error details. Use Err.Clear when you need to reset the object deliberately.
  • Using it to hide a broken macro: If an error is unexpected, suppressing it can leave variables unset or work incomplete. During development, allow unexpected errors to surface and investigate their cause.

One subtle point is that an error handler and an error are not the same thing. On Error Resume Next changes what VBA does when an error occurs; it does not make the underlying operation valid. Likewise, a message saying that a sheet was not found is useful only if the rest of the macro actually stops or follows a suitable alternative path.

Finding and fixing errors while developing

If a macro silently skips work, temporarily remove or comment out the resume-next statement, or put On Error GoTo 0 immediately before the section you want to inspect. Run the macro on a saved copy and note the highlighted line and the error message. You can also set a breakpoint in the Visual Basic Editor, then step through the procedure to see which statement fails and what values are present.

When you do keep local error suppression, make the check visible in the code: capture Err.Number, branch on it, and state the expected outcome. Avoid a bare suppression statement with no nearby explanation. This makes the macro easier to maintain and helps someone distinguish a deliberately optional action from an error that should have stopped execution.

These instructions concern desktop Excel. Excel for the web can open and edit many workbooks but cannot run VBA macros. Excel for Mac supports VBA, though some Windows-specific automation or object-model features may differ; the Visual Basic Editor shortcut can also depend on the Mac keyboard and function-key settings. The VBA error-handling syntax described here is not a Google Sheets or web-formula feature.

Frequently Asked Questions

Is On Error GoTo Next valid in Excel VBA?
No. Use On Error Resume Next to continue after a runtime error, or On Error GoTo label to transfer execution to a valid handler label in the same procedure.

Does On Error Resume Next skip to the next loop iteration?
No. It continues with the next executable statement after the failing statement. To skip a loop iteration, use explicit loop logic such as an If condition or another suitable control-flow statement.

How do I turn On Error Resume Next off?
Use On Error GoTo 0 in the same procedure. Put it immediately after the operation whose error you intended to handle so later errors are not silently suppressed.

How can I tell whether an error occurred?
Inspect Err.Number immediately after the statement that might fail. A nonzero number indicates an error; you can also save Err.Description if you need its message, then clear the error state with Err.Clear when appropriate.

Can Excel for the web run this VBA code?
No. VBA macros run in desktop Excel, not Excel for the web. If a workbook needs automation in a browser, consider Office Scripts where available, but that uses a different programming model and does not run VBA.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.