VBA does not have a Continue For statement. To skip the rest of the current pass and move to the next item, put the work you want to skip inside an If block, or use a GoTo label immediately before the loop’s Next statement. Use Exit For only when you want to stop the loop altogether.
What “next item” means in VBA
A VBA For...Next loop runs its body once for each counter value in its range. When VBA reaches Next, it advances the counter and starts another pass if the loop has not finished. In a For Each...Next loop, Next advances to the next object or value in the collection. In either form, reaching Next normally is how VBA proceeds to the next item.
The question usually means something more specific: “How can I skip the remaining statements for this item, but keep looping?” Languages such as C# and Java have a dedicated continue statement, but VBA does not. A line such as Continue For is not valid VBA syntax. Instead, arrange the loop so that the statements for an item run only when the item meets your condition, or jump to a label at the end of the loop body.
For example, if a loop processes rows and should ignore blank entries, the condition can decide whether the processing code runs. The loop still reaches Next, which advances to the following row. This distinction matters: skipping one item is not the same as ending the whole loop.
Recommended approach: put the work inside an If block
For most code, a conditional block is the clearest way to express “process this item only if it qualifies.” It avoids a jump and makes the rule for processing visible next to the work. For example, with worksheet values in A2:A10, the macro below prints nonblank values to the Immediate window:
Sub PrintNonblankValues()
Dim rowNumber As Long
Dim valueInCell As Variant
' Process only rows whose cell in column A is not blank.
For rowNumber = 2 To 10
valueInCell = ThisWorkbook.Worksheets("Sheet1").Cells(rowNumber, 1).Value2
If Len(CStr(valueInCell)) > 0 Then
Debug.Print rowNumber, valueInCell
End If
Next rowNumber
End Sub
When the cell is blank, the If body is skipped; VBA then reaches Next rowNumber and checks the next row. This example treats a formula that returns an empty string as blank too, because its displayed value has a string length of zero. If the cell might contain an Excel error value, handle that separately before calling CStr; converting an error value to a string can raise a type mismatch.
This pattern is particularly useful when several conditions determine whether an item should be processed. You can combine conditions with And or Or, or use nested If blocks when that makes the rules easier to understand. Keep the main processing statements together inside the qualifying branch.
Alternative: jump to a label before Next
A GoTo label can imitate a continue statement when a loop body is long and putting all of its work inside an If block would make it harder to read. Place the label at the bottom of the loop body, directly before Next. For instance, this skips genuinely empty cells in A2:A20:
Sub PrintNonemptyCells()
Dim cell As Range
' Visit each cell in the specified range.
For Each cell In ThisWorkbook.Worksheets("Sheet1").Range("A2:A20").Cells
If IsEmpty(cell.Value2) Then GoTo NextCell
Debug.Print cell.Address(False, False), cell.Value2
NextCell:
Next cell
End Sub
If IsEmpty is true, execution jumps to NextCell:. The next statement advances the For Each loop. Otherwise, the value is printed and execution reaches the same label in the ordinary way. The label must be inside the procedure, and its name must be unique in that procedure.
Notice the difference between IsEmpty and checking whether a cell looks blank. IsEmpty detects a cell with no value; a formula returning "" is not an empty cell, even though it appears blank. Choose a test that matches your data. Also keep the jump local: jumping to the loop’s end is easier to follow than jumping to a distant label or using many labels throughout a procedure.
How to skip items in a For Each loop
For Each is common in Excel macros because it can visit every cell in a range without manually incrementing a row number. The same two techniques apply: wrap the work in a condition, or use a label immediately before Next. A conditional version is often easiest to maintain:
Sub ProcessPositiveValues()
Dim cell As Range
' Process numeric values greater than zero in B2:B20.
For Each cell In ThisWorkbook.Worksheets("Sheet1").Range("B2:B20").Cells
If IsNumeric(cell.Value2) Then
If cell.Value2 > 0 Then
Debug.Print cell.Address(False, False), cell.Value2
End If
End If
Next cell
End Sub
The nested checks avoid comparing text or an empty cell directly with zero. If your source range can contain Excel error values, test for those before using functions or comparisons that do not accept errors. For a collection other than worksheet cells, the idea is identical: put the code that applies to each object inside the condition that determines whether that object should be handled.
Skip one pass versus Exit For
Exit For is a real VBA statement, but it does not mean “go to the next item.” It immediately leaves the nearest enclosing For or For Each loop. Use it when the task is complete or continuing would serve no purpose, such as stopping a search after finding the first match. Use an If block or a local GoTo when only the current item should be ignored.
For example, in a search loop, a match might justify Exit For because there is no reason to keep searching. In a loop that validates every row, finding one invalid row usually should not end the loop if later rows still need checking. In that case, record or report the problem and let the loop reach Next.
There is another common misunderstanding: writing Next rowNumber does not itself skip the current item. It completes the current pass and advances the counter. If execution has already reached that line, the statements above it have already run. To skip those statements, control flow must avoid them or jump over them.
Handling nested loops carefully
In a nested loop, each Next corresponds to one loop level. A GoTo label placed immediately before the inner loop’s Next skips to the next inner item, not the next item of the outer loop. That is usually what you want when rejecting one column value while continuing to inspect the remaining columns in the same row.
If you want to skip the rest of an outer-loop pass, do not accidentally target the inner loop’s end. A conditional structure can make the intended level clearer. For example, use an outer condition to decide whether to enter the inner loop at all, or put the remaining outer-loop work in a branch that runs only when the outer item qualifies. Labels such as NextRow and NextColumn can clarify intent when a short jump is genuinely useful, but they do not change which loop’s Next is reached.
Be cautious about jumping into structured code. Keep a label in the same procedure and at the same loop level as the code that uses it; do not jump into the middle of another loop or into a block that should only be entered through its normal condition. When the control flow is difficult to trace, rewrite it with If blocks rather than adding more jumps.
Choosing the clearest pattern
Use the simplest pattern that communicates why an item is being skipped. As a rule of thumb:
- Use an
Ifblock when the processing is short or when the qualifying condition is central to understanding the loop. - Use a
GoTolabel at the loop end when the body is long, an early rejection keeps it readable, and the target is immediately before the correctNext. - Use
Exit Forwhen the entire loop should end, not merely the current pass. - Consider a separate procedure for a large unit of work, so the loop can test an item and call the procedure only for qualifying items.
VBA also has Do...Loop loops, but they do not add a Continue Do statement. The same general choices apply: structure the body with a condition, or use a carefully placed label if a jump is warranted. In every case, make sure the loop’s normal ending statement still runs so its counter or collection advances as intended.
Run and inspect the example safely
To view output from Debug.Print, open the Visual Basic Editor and show its Immediate window. In Excel for Microsoft 365 on Windows, Alt+F11 opens the editor; Ctrl+G in the editor shows the Immediate window. On Mac, the editor shortcut is generally Option+F11 (some keyboards require Fn as well); menu availability and shortcut behavior can vary with macOS keyboard settings. The Immediate window is for diagnostic output, not a worksheet result.
Before running any macro, save a copy of the workbook. VBA changes cannot be undone with Ctrl+Z, and a macro that writes to cells may change many values at once. The examples above only print values, but the same precaution is appropriate when adapting them to edit a workbook. If you add a macro to a workbook, save it in a macro-enabled format such as .xlsm if you need to retain the VBA project.
Frequently Asked Questions
Does VBA support Continue For?
No. Continue For is not a VBA statement. Use a conditional block or a GoTo label just before the loop’s Next.
How do I skip to the next row in an Excel VBA loop?
Put row-processing code inside an If condition, so it runs only for rows that qualify. Alternatively, jump to a label immediately before Next rowNumber to skip the rest of the current row’s loop pass.
Can I use Exit For to skip one item?
No. Exit For ends the nearest For or For Each loop. Let execution reach Next to move on while keeping the loop active.
Does GoTo Next skip the item or the whole loop?
A jump to a label before Next skips the remaining statements in the current pass. The Next statement then advances to another item. A jump to a label after the loop would instead leave the loop.
How do I skip a blank cell in For Each?
Test the cell inside the loop and run the processing code only when it is not blank. Use IsEmpty for truly empty cells; use a value or formula-result test if cells containing formulas that return an empty string should also be skipped.
Related
- Power Query Circular Reference: Causes and Fixes
- Excel Data Validation Source: Lists, Ranges, and Rules
- Excel Data Validation Rules: How They Work and When to Use Them
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Hide Column VBA: Methods, Examples, and TroubleshootingTo hide a column with VBA in Excel, set that column’s Hidden property to True, such as Worksheets("Data").Columns("C").Hidden…
- VBA Function Structure: Syntax, Examples, and ScopeA VBA function is a procedure that performs work and returns a value. Its basic structure is Function…
- VBA Code to Update a PivotTable in Excel AutomaticallyTo update one PivotTable in Excel for Microsoft 365 on Windows, call its RefreshTable method from a VBA…
- Google Sheets Macros: How They Work and What They Can DoYes. Google Sheets has macros that can record repeated actions and replay them later; unlike Excel macros, Sheets…
- VBA Copy PasteSpecial: Values, Formats, and MoreIn Excel VBA, copy a range and call PasteSpecial on the destination to paste only values, formats, formulas,…
- VBA Delete Rows in a Range: Safe Methods and ExamplesTo delete entire worksheet rows that intersect a range, use the range’s EntireRow property and call Delete, for…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.