OzGrid

Excel VBA Loops Explained

< Back to Search results

 Category: [Excel]  Demo Available 

 

Excel VBA Loops Explained

 

VBA Code Loops, Repeat a Block of VBA Macro Code

Got any Excel/VBA Questions? Excel Help

VBA Loops

Loops are used in Excel VBA Macro code to tell Excel to repeat a block of code until a condition is TRUE, FALSE, a specified number of times, or to loop through a Collection or Array. There are many type of loops one can choose from. That one that you need will depend on exactly what it is you are wanting to do. See the list below on the different types of loops.

Do Loops

Syntax
Do
 [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop

Or, you can use this syntax:
Do

[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]

 

For...Next Loop

Syntax
For counter = Start To end [Step step]
[statements]
[Exit For]
[statements]
Next [counter]

 

For...Each Loop

Syntax
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]

See also:

Loop All Worksheets/Sheets in Workbook & Apply Code
Used to Loop Through a Collection or Array
For Loop
For Loop Step

 

See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 

 

 

 

 

 


Gallery



stars (0 Reviews)