Using the For/Next loop

Repeats a group of statements a specified number of times.


Example-1
1)

For I = 1 to 50 Step 2
A = I * 2
Debug.Print A
Next I


Example-2
2)

For I = 50 to 1 Step -2
A = I * 2
Debug.Print A
Next I


In this example, the variable I initializes at 1 and, with each iteration of theFor/Next loop, is incremented by 2 (Step). This looping continues until I becomesgreater than or equal to its final value (50). If Step is not included, the default valueis 1. Negative values of Step are allowed.
·  You may exit a For/Next loop using an Exit For statement. This will transferprogram control to the statement following the Next statement.

Popular posts from this blog

50 Excel VBA Oral Interview Questions