Skip to content

VBA170 — Exit For not within For...Next

Severity: 🔴 error Category: control_flow Phase: 2.11

Description

Exit For is only valid inside a For / For Each loop.

Failing example

Sub S()
    Exit For
End Sub

Compliant example

Sub S()
    For i = 1 To 10
        Exit For
    Next i
End Sub

How to fix

Remove the Exit For or place it inside a For loop.


Source: src/rules.py — entry VBA170.