Macros/vba



For loop





A loop is a sequence of instructions that will carry on until a certain condition is reached.


A for loop allows us to set a start and end point and "do" something to every cell in the range.


Here's one of those bad boys in action:







Simple loop macro



Sub ForLoop()
'this is the counter
Dim i As Integer
'start of for loop
For i = 1 To 5
'set cell value. [Cell (1,1) is A1, Cell (2,1) is A2.... etc...]
Cells(i, 1).Value = "We are looopin now!"
'wait a second to show the loop!
Application.Wait (Now + #12:00:01 AM#)
Next i
End Sub






Thank you for joining me in this journey. I will be digging deeper into loops as the site matures and users request it.

‚Äč

Best,

Tom