How to Stop a Loop in VBA

VBA is a programming language developed by Microsoft. VBA syntax is simple and easy to learn. Although not as complex as other programming languages, VBA still contains many of the same constructs other programming languages do, including conditional statements, functions and loops. Loops repeat a set of statements for a "true" or "false" condition. In many cases, due to programmer error or system problems, a loop may start repeating itself endlessly. You can stop an endless loop a few different ways.

Instructions

    • 1

      Press "Esc" on your keyboard. This will stop the loop.

    • 2

      Press "Ctrl+Break" on your keyboard. This will also stop the loop.

    • 3

      Use an "Exit" statement in your VBA loop.

      Here is an example of the "Exit" statement being used in a "For" loop.

      Dim indexA, indexB

      For indexA = 1 to 2

      For indexB = 1 to 100

      If indexB > 5 Then

      Exit For

      End If

      document.write (indexB & " ")

      Next

      Next

Related Searches:

References

Resources

Comments

Related Ads

Featured