Skip to content

VBA174 — For Each control variable must be Variant or object

Severity: 🔴 error Category: control_flow Phase: 2.11

Description

A For Each control variable cannot be a primitive scalar type.

Failing example

Dim i As Long
For Each i In coll
Next i

Compliant example

Dim v As Variant
For Each v In coll
Next v

How to fix

Declare the control variable as Variant, Object, or a class type.


Source: src/rules.py — entry VBA174.