Excel VBA If Then GoTo Next Loop? The Safe Pattern

VBA & macros · Updated November 21, 2026

Yes. In Excel VBA, use an If...Then GoTo statement to jump to a label placed immediately before the loop’s Next or Loop statement; the loop statement then advances or checks the loop as usual. VBA does not provide a Continue For or Continue Do statement, so a forward jump to a clear, nearby label is one way to skip the rest of an iteration.

What “GoTo next loop” means in VBA

When people ask whether VBA can “go to the next loop,” they usually mean: if a condition is true, stop the current iteration’s remaining work and start the next iteration. VBA has a Next keyword, but it is not a target that you can jump to by writing GoTo Next. Instead, place a label just before the loop-closing statement and jump to that label.

For a For loop, the label goes before Next. Reaching Next still performs the normal loop bookkeeping: a counter changes, or a For Each loop moves to its next item, and VBA determines whether another iteration is due. For a Do loop, put the label before Loop, so the loop condition is handled normally.

This is different from Exit For or Exit Do. Those statements leave the loop entirely. A jump to a label before the loop-closing statement skips only the remaining statements in the current pass.

Basic syntax and a working example

The general pattern is If condition Then GoTo label, followed by the label and colon inside the same procedure. The example below prints positive numeric values from a range and skips the remaining work for values that are zero or negative. It assumes the inspected cells contain numbers.

Option Explicit

Sub PrintPositiveValues()
    Dim cell As Range

    ' Check each value in the selected worksheet range.
    For Each cell In ActiveSheet.Range("A2:A100")
        If cell.Value2 <= 0 Then GoTo SkipCell

        ' This runs only for values greater than zero.
        Debug.Print cell.Address, cell.Value2

SkipCell:
    Next cell
End Sub

For instance, if A2 contains 8, the macro prints that cell’s address and value. If A3 contains 0 or -4, VBA jumps to SkipCell, reaches Next cell, and proceeds to the next cell without printing the skipped value. The label is part of the procedure, and the colon marks where execution resumes.

Before running any macro, save a copy of the workbook. VBA macro actions cannot be undone with Ctrl+Z, so a backup is important if you adapt the example to edit or delete worksheet data.

How the jump affects loop flow

A GoTo statement transfers execution to a label; it does not itself advance a loop counter or select another item. In the example, the transfer skips Debug.Print, but control then reaches Next cell. That loop statement is what moves the For Each loop forward. If the label were placed after the loop instead, the jump would leave the loop rather than continue its normal iteration.

In a For loop, the equivalent arrangement is a label before Next i. In a Do While or Do Until loop, put the label before Loop. Reaching the bottom of a loop is important: it lets VBA evaluate the loop’s condition or update its counter. Do not replace the loop-closing statement with a jump and assume VBA will do that work automatically.

There is no requirement that the label be named Next. Choose a distinctive name such as SkipCell, ContinueRow, or SkipItem. Labels must be unique within a procedure. They cannot be used to jump into a different procedure, and a jump cannot act like a reusable function call.

Using the pattern with a For loop

This example skips even numbers and prints odd numbers. The label sits immediately above Next i, making it clear that the jump means “skip the rest of this pass.”

Option Explicit

Sub PrintOddNumbers()
    Dim i As Long

    For i = 1 To 10
        If i Mod 2 = 0 Then GoTo SkipItem

        Debug.Print i

SkipItem:
    Next i
End Sub

The output is 1, 3, 5, 7, and 9. When i is even, the jump bypasses the print statement; when it is odd, execution naturally reaches the same label after printing. In both cases, Next i increments the counter. The condition is written on one line because it contains only one action; for a more involved condition, a multiline If block can make the logic easier to scan.

Cleaner alternatives to GoTo

A jump is useful when it avoids deeply nested code, but for a short loop body, a positive If condition is often easier to read. Instead of jumping past work when a value fails a test, place the work inside a block that runs only when the value passes.

Option Explicit

Sub PrintPositiveValuesWithoutGoTo()
    Dim cell As Range

    For Each cell In ActiveSheet.Range("A2:A100")
        If cell.Value2 > 0 Then
            Debug.Print cell.Address, cell.Value2
        End If
    Next cell
End Sub

This version has the same result for numeric cells: it prints values greater than zero and does nothing for the others. It may be preferable when there is only one conditional action. If a loop has many lines of work that should be skipped together, a clearly named label near the loop end can reduce indentation and make the intended path easier to follow.

Another option is to reverse the condition. For example, instead of saying “if the value is not usable, jump to the end,” write “if the value is usable, process it.” Use whichever form makes the normal path and skip condition most obvious to a reader. Avoid layering several jumps into one loop; multiple labels can turn a simple pass through data into difficult-to-trace control flow.

Nested loops and choosing the right exit

With nested loops, a label before the inner loop’s closing statement skips the rest of the current inner iteration only. It does not automatically skip the outer iteration. This distinction matters when processing, for example, every cell in each row: jumping to a label before the inner Next advances to the next cell, while jumping to a label before the outer Next can leave the inner loop and move on to another row.

Keep labels close to the loop they belong to and name them accordingly, such as SkipCell for an inner cell loop. If the intended action is to stop the inner loop entirely, use Exit For inside that loop. If the intention is to stop the whole procedure, that requires a different control-flow choice. A GoTo label is not a substitute for identifying which loop should continue or end.

For nested loops with several skip conditions, consider using an If...ElseIf...Else structure or moving a repeated task into a separate procedure. A small amount of structure can be clearer than a network of labels, especially when future changes might add code between the label and the loop’s closing statement.

Common mistakes and debugging checks

  • Trying GoTo Next: Next is a loop statement, not the label in this pattern. Use a custom label such as SkipRow before Next rowNumber.
  • Putting the label in the wrong place: A label after the loop-closing statement can cause execution to leave the loop. Put it immediately before the correct Next or Loop.
  • Using Exit For to skip one item: Exit For ends the current For loop. Use a label before Next, or an If block, when later items still need processing.
  • Reusing a label name: Labels need distinct names within their procedure. Descriptive names also help readers identify which loop the jump targets.
  • Overlooking data types: A comparison such as cell.Value2 <= 0 assumes comparable numeric values. Text, worksheet errors, or other unexpected contents may require validation before the comparison.
  • Confusing this with error handling: On Error GoTo directs VBA to an error-handling label when an error occurs. It is a separate feature from a conditional jump used to skip an iteration.

If the code behaves unexpectedly, step through it in the VBA editor and watch whether execution reaches the skip label, then confirm it reaches the intended loop-closing statement. Also check the label’s position and the loop variable or condition. A breakpoint on the line after the label can help establish whether the loop continues as intended.

When to use this pattern

Use a forward jump to a loop-end label when it makes a meaningful skip path simpler, particularly when several statements should be bypassed together. It is also useful when converting pseudocode that describes a “continue” action into VBA, which lacks a dedicated continue statement. Keep the jump local, the label descriptive, and the distance between the jump and label short.

Prefer ordinary conditional blocks when they express the same logic without excessive nesting. Reserve Exit For and Exit Do for cases where the loop should end, not merely skip one item. These choices make it easier to review the macro and reduce the risk that a later edit changes the meaning of a jump.

Frequently Asked Questions

Does VBA support Continue For?
No. Excel VBA does not have a built-in Continue For or Continue Do statement. A label before Next or Loop, or a conditional block around the work, can provide the same practical skip behavior.

Can I write GoTo Next in Excel VBA?
Not as a way to continue a loop. Use GoTo with a valid label name, such as GoTo SkipRow, and place SkipRow: before the loop’s closing statement.

Does GoTo SkipCell move to the next cell by itself?
No. It moves execution to the label. The following Next cell statement advances the For Each loop to the next item.

What is the difference between GoTo and Exit For?
A jump to a label immediately before Next skips the rest of the current iteration and allows the loop to continue. Exit For ends that loop completely.

Can I use this in a Do loop?
Yes. Put the label before the appropriate Loop statement. Reaching Loop then applies the loop’s normal condition, so the loop continues or ends according to that condition.

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.