The Microsoft Excel FOR...NEXT statement is used to create a FOR loop so that you can execute VBA code a fixed number of times.
The FOR...NEXT statement is a built-in function in Excel that is categorized as a Logical Function. It can be used as a VBA function (VBA) in Excel.
Syntax
FOR counter = start TO end [Step increment]
{...statements...}
NEXT [counter];
Note: counter can be changed using “STEP”.
Parameters or Arguments:
Parameter/Arguments
|
Description
| |
counter
|
Required in the For statement. Numeric variable. The control variable for the loop. For more information, see Counter Argument later in this topic.
| |
datatype
|
Optional. Data type of counter.
| |
start
|
Required. Numeric expression. The initial value of counter.
| |
end
|
Required. Numeric expression. The final value of counter.
| |
step
|
Optional. Numeric expression. The amount by which counter is incremented each time through the loop.
| |
statements
|
Optional. One or more statements between For and Next that run the specified number of times.
| |
Continue For
|
Optional. Transfers control to the next loop iteration.
| |
Exit For
|
Optional. Transfers control out of the For loop.
| |
Next
|
Required. Terminates the definition of the For loop
|
Click Here for examples: