Lesson 10 - For Next

Outcome of this Lesson

We “Loop” around code when we run a block of VBA over and over.

With Loops you can do useful actions like this:

  • Go through a lot of cells and reformat all of them the same way
  • Go through every worksheet and change its color

For … Next loops are a simple type of loop.

The looping is controlled by a counter that starts at one value and stops at another.

The code lines between For and Next are repeated every time VBA goes around the loop.

In Lesson 10 we look at these examples:

  • For Next Loop (Simple)
  • For Next Loop with Step
  • For Next Loop to Shade Every Third Row on Worksheet
  • For Next Loop to Clear Shading

Download the workbook

After you watch the video, I recommend you open the example workbook.

And play around with declaring constants.

You can get the workbook at the beginning of Module 5 (Downloads).

Refer to the PDF Handout

For a handy summary of the key concepts, look at the Module 5 PDF Handout.

You can get the PDF Handout at the beginning of Module 5 (Downloads).



Write your comments and feedback below

  • If you have questions or comments about this lesson, write it in the section below.
  • Alternatively you can email the instructor Victor at [email protected]

Complete and Continue  
Discussion

0 comments