VBA Go To Next Iteration: Skip Loop Code Correctly

VBA & macros · Updated November 18, 2026

VBA has no built-in Continue For or Continue Do statement. To move to the next iteration, either put the remaining loop work inside an If block that runs only when an item should be processed, or use GoTo to jump to a label immediately before the loop’s Next or Loop statement.

How VBA loop control works

A loop repeats a block of code while a counter, collection, or condition tells it to continue. In a For loop, execution reaches Next to advance the counter and begin the next pass. A For Each loop reaches Next to move to the next item in its collection. A Do loop reaches Loop to test its condition or continue, depending on how the loop is written.

Many languages provide a keyword such as continue for skipping the rest of the current pass. VBA does not. In VBA, reaching the end of the loop body naturally advances the loop, so the key is to bypass the work you do not want to run while still allowing control to reach Next or Loop.

For example, if a loop examines many spreadsheet rows but should ignore blank rows, it can check each row and run its processing code only when the row contains something useful. That approach is often clearer than jumping around the procedure.

Prefer an If block for straightforward skips

The most readable pattern for a simple skip is to put the work inside an If block. The loop still reaches its normal ending, but the processing code is omitted when the condition says to skip the item. This avoids adding a label and makes the condition visible next to the code it controls.

For example, the following macro scans column A of a worksheet named Data. It processes nonblank cells and ignores blank ones. The sample uses a placeholder comment for the work to perform; replace it with the actual task.

Sub ProcessNonblankRows()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long

    ' Save a copy of the workbook before running this macro.
    Set ws = ThisWorkbook.Worksheets("Data")
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    For i = 1 To lastRow
        If Len(Trim$(CStr(ws.Cells(i, "A").Value))) > 0 Then
            ' Replace this comment with the row-processing code.
        End If
    Next i
End Sub

When column A contains only spaces, Trim$ removes those spaces and the test treats the cell as blank. This example assumes the cells contain ordinary values; a cell containing an Excel error value needs separate handling before converting it with CStr. If your actual task uses several statements, keep all of them inside the If block so they are all skipped together.

Use GoTo as a continue-style jump

If a loop body is long and wrapping the remaining work in an If block would require a large indentation change, a label can imitate a continue statement. Put the label immediately before the loop-ending statement, then jump to it when the current item should be skipped. The label must be in the same procedure.

Sub SkipBlankRowsWithLabel()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim i As Long

    ' Save a copy of the workbook before running this macro.
    Set ws = ThisWorkbook.Worksheets("Data")
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    For i = 1 To lastRow
        If Len(Trim$(CStr(ws.Cells(i, "A").Value))) = 0 Then GoTo NextRow

        ' Replace this comment with the work for nonblank rows.

NextRow:
    Next i
End Sub

When VBA executes GoTo NextRow, it skips the intervening statements and reaches Next i. The Next statement still runs, so i advances normally. This placement is what makes the jump resemble a “continue” operation rather than an exit from the loop.

Use a descriptive label that makes its location obvious, such as NextRow or ContinueItem. VBA labels end with a colon, and label names must be unique within their procedure. Avoid naming a label simply Next, which is also a VBA keyword and makes the code harder to read.

Skipping iterations in For Each loops

The same two patterns work with For Each. An If block can process only the items that meet a condition. Alternatively, a label directly before Next can skip the rest of the current pass. VBA advances the collection item when execution reaches Next; do not try to increment or reposition the loop variable yourself.

For instance, when inspecting worksheet cells, you might want to ignore cells that are empty and process the others. In a short loop, an If condition is usually easiest to follow. A label can help when the body has multiple checks and substantial processing below them. The important point is that the label belongs inside the loop and immediately precedes its matching Next.

Be careful with nested loops. A label before the inner loop’s Next skips only the remaining statements in the current inner iteration. It does not skip the outer iteration. To skip a pass of the outer loop, control must reach a label positioned before the outer loop’s own Next, and the code must be structured so that this jump does not cross into or out of a loop unexpectedly.

Skipping an iteration in a Do loop

For a Do loop, place a continue-style label immediately before its Loop statement. If the loop tests its condition at the top, reaching Loop sends control back to that test. If it tests at the bottom with Loop While or Loop Until, reaching the statement evaluates that condition.

Before using this pattern, check whether the statements you skip include essential updates. A counter, file position, or other state may need to change on every pass. If a jump bypasses that update, a Do While condition might remain true indefinitely and the macro could appear to hang. One remedy is to perform the required update before the jump; another is to restructure the loop so that the update is always reached.

A Do loop is especially sensitive to this issue because it has no automatic counter advancement like a For loop. Trace every path through the body and confirm that each one either changes the state needed for termination or reaches a condition that can end the loop.

Choosing between If and GoTo

Neither pattern is universally best. Choose the one that makes the control flow easiest to understand for the person who will maintain the macro. A simple eligibility check usually calls for an If block. A label can be reasonable when the loop body is already long, several conditions should skip to the same point, or restructuring the code would make it less clear.

  • Use an If block when there is a short section of work to run only for qualifying items. It keeps the condition and its work together.
  • Use a label when a jump cleanly bypasses a lengthy remainder of the current iteration and the label is placed beside the correct loop ending.
  • Restructure the loop if many jumps, deeply nested conditions, or unclear labels make it difficult to tell which statements run for each item.

For example, if a loop checks whether a row is eligible and then runs three short statements, an If block is likely clearer. If a long processing section follows several separate “ignore this row” checks, a single well-named label before Next may be simpler than adding layers of nested If statements. Keep labels local and use them sparingly; they are a control-flow tool, not a substitute for a clear structure.

Common mistakes and debugging checks

A common mistake is placing the label after the loop-ending statement or outside the loop. That does not continue the current iteration in the intended way. For a For loop, the target should be immediately before its matching Next; for a Do loop, place it before the relevant Loop. Then check that the jump cannot skip code needed to prepare the next pass.

Another mistake is confusing “skip this item” with “stop looping.” Exit For ends the entire nearest For loop, and Exit Do ends the nearest Do loop. They are not replacements for a continue-style skip. Use them only when you want to leave the loop altogether.

When debugging, step through the macro with the Visual Basic Editor’s debugging tools and watch the loop variable and the line that executes after the label. Confirm that skipped items do not run the processing statements, that the loop still advances, and that termination conditions remain reachable. If a jump produces an error, inspect whether it crosses a procedure boundary or enters a restricted structure such as a With block. Keeping the label adjacent to the loop ending helps avoid confusing jumps.

Macros can change workbook data, and their actions cannot be reversed with Ctrl+Z. Save a separate copy of the workbook before running a macro that edits data, especially while you are testing loop logic. Test on a small range or a duplicate sheet before applying the code to a full workbook.

Alternatives when a loop needs redesign

If a loop has many reasons to skip work, a small helper function can sometimes make the decision easier to read. For example, a function could return whether a row should be processed, leaving the loop to act on that result. This is useful when the same eligibility rule appears in several places, but it may be unnecessary overhead for a one-line condition.

Another option is to organize the code into clear stages: first validate the current item, then process it only if it passes validation. In VBA, this can mean using nested If blocks or moving the processing into a separate procedure. Avoid creating many tiny procedures solely to imitate a missing language keyword; choose a structure that makes the actual rule and its consequences clear.

There is no special VBA setting to enable Continue For or Continue Do. If code copied from another language includes those statements, rewrite that control flow using an If block or a local GoTo label. This distinction matters when adapting examples from languages such as VB.NET, where loop-control features differ from VBA.

Frequently Asked Questions

Does VBA have a Continue For statement?
No. VBA does not provide Continue For or Continue Do. Put the remaining work inside an If block, or jump to a label immediately before the loop-ending statement.

Can I use GoTo to skip to the next iteration?
Yes. Put a label before the matching Next or Loop and use GoTo to jump there. Keep the label in the same procedure and within the intended loop.

Is Exit For the same as skipping an iteration?
No. Exit For ends the entire nearest For loop. To skip only the current pass, use an If block or a continue-style label.

How do I skip a blank row in a VBA loop?
Test the relevant cell before processing the row. Put the processing code inside a condition that is true for nonblank values, or use a label before Next to jump over that code when the cell is blank.

Why does my Do loop run forever after I skip code?
The jump may be bypassing the counter or state update that makes the loop condition eventually false. Ensure every path updates the necessary state or reaches a condition that can terminate the loop.

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.