Description
The For Each...Next statement repeats a group of statements for each element in an array or collection.
This statement has the following form:
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]
Parameter | Description |
---|---|
element | (required) Specifies a variable used to iterate through the elements of the collection or array. For collections, element can only be a Variant variable, a generic Object variable, or any specific Automation object variable. For arrays, element can only be a Variant variable |
group | (required) Specifies the name of an object collection or array |
statements | (optional) One or more statements that are executed on each item in group |
Examples
The following example shows the basic use of this statement:
Dim numbers(2)
numbers(0) = "one"
numbers(1) = "two"
numbers(2) = "three"
For Each x In numbers
Msgbox(x)
Next
This produces the following result (each line in a separate pop-up message box):
one
two
three
Miscellaneous Information
Supported in Version: | 2.0 |
---|