For Each...Next
This statement repeats a group of statements for each element in an array or collection.
Syntax
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]
Parameters
- element
- Variable used to iterate through the elements of the collection or array. For collections, element can be only a Variant variable, a generic Object variable, or any specific Automation object.
- group
- Name of an object collection or array.
- statement
- One or more statements executed on each item in group.
Remarks
You can nest For Each...Next loops by placing one For Each...Next loop within another. However, each loop element must be unique.