09 – Loops

In this post, we will be taking a look at Loops.

A loop is a block of code that executes again and again until either an expression equates to false or is broken by way of an Exit statement. What makes loops useful is that they can work with arrays and collections, they can perform tasks over and over until a condition is met and they can perform calculations over and over until you force them to stop. There are several ways to express this need to loop and VBA isn’t short on constructs for doing it.

List of topics covered:

  • For…Next
  • For i = 1 to 10 : {code block} : Next
  • For…Step…Next
  • Use Step to Count Backwards
  • Using Dynamic startValue, endValue and stepValues
  • For…Each
  • Using Loops with Collections
  • Demonstrate with Arrays
  • Exit For
  • While…Wend
  • While (false)
  • Exit While
  • Loop/Do…Until/While
  • Nesting Loops
  • Nested Loops and Multidimensional Arrays
  • DoEvents

In order to view the rest of this content you will need to register for a premium account. Click here for your free trial.

As always, a site wouldn't be anything without its users so please feel free to comment! We welcome any comments you have on the material and any suggestions you may have for future content.

In our humble opinion, it is worth commenting just so you can play with Fun Captcha below!