For Loop

< Back to Search results

 Category: [Excel]  Demo Available 

For Loop


For Loop. For Next...Loop No Step

Got any Excel Questions? Free Excel Help

For Loop

A For Loop is used to repeat a block of code a specified number of times. We can force an exit from a For loop with the Exit For Statement. E.g. If lNum=5 Then Exit For

Sub For_Loop_No_Step()

Dim lCount As Long, lNum As Long

    For lCount = 1 To 9

        lNum = lNum + 1

    Next lCount


     MsgBox "The For loop made " & lCount & " loop(s). lNum is equal to " & lNum

End Sub

For...Next Loop

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


See also:

Excel VBA: Extract Word From a Text String
Excel VBA: Find Number Between 2 Numbers
Find Method to Find Dates
Excel VBA Find Method
Force Text to Upper Case/Proper Case
Used to Loop Through a Collection or Array


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.


stars (0 Reviews)