Skip to content

VBA172 — Next control variable mismatch

Severity: 🔴 error Category: control_flow Phase: 2.11

Description

The variable on Next x must match the loop's For counter.

Failing example

For i = 1 To 10
    Debug.Print i
Next j

Compliant example

For i = 1 To 10
    Debug.Print i
Next i

How to fix

Use the same variable as the For counter, or a bare Next.


Source: src/rules.py — entry VBA172.