Subscriber only lesson.
Sign up to this course to view this lesson.
About this lesson
Running a loop a set number of times.
Download this lesson’s exercise file.Loops: Looping x iterations with For x to y loops.xlsm
Loops: Looping x iterations with For x to y loops
Looping x number of times use For X loops
When to use
When you wish to loop a specific number of times, and want to avoid the dangers of runaway Do loops
Syntax: Looping from start to end
For <variable> = <first> To <last>
Syntax: Looping from end to start
For <variable> = <last> To <first> Step -1
Hints & tips
- The <last> value should be the largest value you want to loop to
- The <first> value should be the smallest value you want to start the loop at
- Step does not need to be -1; you could step -2, -5, -10 or some other iteration
- Step does not need to be negative; you could step 2, 5, 10 or some other iteration
- Including the variable on the Next line is optional but can help make your code more readable
- you may exit a loop early by using the keywords "Exit For"
Lesson notes are only available for subscribers.