VBA - While loops

While loops run until a criteria is met. This can create cases where to loop will run indefinitely, as a programmer you should consider cases where this might happen.

this example loops until a variable is great than 10.

This returns 55:
Note that this loop performs the same task as the example in the "for loop".

I would reccomned playing with both examples to understand how they both create the same result.

Code Snippet:

Sub a10_2_loops_1()

Dim i As Integer
Dim j As Integer

j = 0

Do While i < 10
  i = i + 1
  j = j + i


MsgBox j

End Sub

Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.

Must Read Articles

VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.
Installing VBA and First Program - What do you need to start using visual basic application VBA.