Skip to content

VBA173 — For control variable already in use

Severity: 🔴 error Category: control_flow Phase: 2.11

Description

A nested For loop reuses the counter variable of an enclosing loop.

Failing example

For i = 1 To 3
    For i = 1 To 3
    Next i
Next i

Compliant example

For i = 1 To 3
    For j = 1 To 3
    Next j
Next i

How to fix

Use a distinct counter variable for the inner loop.


Source: src/rules.py — entry VBA173.