Runtime Error 92: “For loop not initialized,” explained and fixed

Error 92, “For loop not initialized”, means execution arrived inside a For...Next loop without passing through the For statement that sets it up, or the loop's control state was disturbed. The overwhelming cause is a GoTo (or an error-handler Resume aimed at a line) that lands in the middle of a loop body: the counter was never initialized, so the Next has nothing to work with. It is a control-flow bug, and the cure is restructuring so loops are entered only through their For line.

For people who just run the program

  1. Expect it in old or heavily patched macros. Error 92 lives where years of GoTo-based fixes have been layered over original loops; freshly written structured code rarely produces it.
  2. Note the button or step. It fires at a specific jump, so the action identifies which code path takes the illegal shortcut.
  3. Do not try to “warm up” the macro by running parts first. Loop state does not carry between runs; the jump fails identically every time.
  4. Send the maintainer the error and the step. This number tells an experienced VBA reader exactly what shape of bug to look for.

For people who write the code

  1. Find the jump that enters the loop. Search for GoTo and Resume statements whose target label or line sits between a For and its Next:
  2. For i = 1 To 10
        ' ...
    SkipAhead:
        total = total + i
    Next i
    ' A GoTo SkipAhead from above lands inside the loop: error 92 at Next.
  3. Replace jump-in patterns with flags or restructured flow. If code needs to “start halfway,” initialize the counter and use a Do loop with explicit setup, or run the For from the beginning with an If that skips early iterations' work.
  4. Never Resume into a loop from a handler. An error handler that Resumes to a line inside a loop the error interrupted can produce the same uninitialized state. Resume to the For line itself, or restructure so the loop body is a called procedure with its own handler.
Error 92 can also appear when a loop variable is abused as storage. Code that passes the counter ByRef into procedures that run their own loops on it corrupts the outer loop's bookkeeping. Treat the control variable as read-only outside the For statement's own step.

If it still happens

If no jumps exist, suspect event-driven re-entry: a loop that triggers events (changing cells, showing forms) whose handlers jump back into the same procedure, tangling two activations of the loop. Guard the procedure with a static “running” flag and log entries to confirm.

Common questions

Why does jumping into a loop fail if the counter has a value? Because For sets up more than the counter: it records the end value, the step, and the return point for Next. Entering mid-loop skips that setup, so Next has no initialized loop to continue.

Is GoTo always wrong in VBA? No, but jumping into a block from outside is the dangerous direction. Jumping out (like Exit patterns and error handlers) is safe; jumping in skips initialization, which is what error 92 reports.

Related errors

Runtime Error 10 · Runtime Error 457 · Runtime Error 20