Wauvel

Excel like a finance pro.

← The library

VBA · Control flow

GoTo

Jumps to a label; used almost only with On Error.

OccasionalDifficulty 1150 · Proficient
Practice · 1 questions →

When to use it

GoTo jumps to a label in the same procedure. Modern VBA uses it almost only in On Error GoTo; anywhere else it makes code hard to follow.

The code

Code
On Error GoTo Handler

Worked examples

  • Error handler

    On Error GoTo Handler ... Handler: MsgBox Err.Description The one accepted use

    Error handling.

  • Cleanup jump

    GoTo Cleanup ... Cleanup: Application.ScreenUpdating = True Jumping to shared cleanup code

    Tolerable, but Exit patterns are clearer.

  • Label syntax

    Labels end with a colon: Handler: A label marks the target

    Syntax.

Worth knowing

  • Replace GoTo logic with If, Do, and Exit.
  • Labels must be unique within the procedure.
  • GoSub and Return exist but are obsolete.

Where it goes wrong

  • Jumping backwards creates loops nobody can see.
  • Jumping into or out of a With block is not allowed.

Related

Learn the moves here — or let Wauvel run them on your numbers.

Meet your AI CFO →

One CFO-grade Excel tip a week

A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.