Lesson 11 - For Each Next 1

Outcome of this Lesson

(The one with the cute dogs!)

For Each … Next loops are very similar to For … Next loops.

Instead of looping through a counter, the For Each loops through every object in a collection of objects.

For example, Excel has a collection of all open workbooks (the Workbook collection), and each workbook has a collection of worksheets (the Worksheets collection).

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

In Lesson 11 we look at these examples:

  • For Each … to Hide Sheets
  • For Each … to Show Sheets


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