Forum Discussion
Satyendra Belwanshi
Apr 21, 2017Copper Contributor
What is Loop? How apply loop in VB?
Hi Experts,
Please explain loop with example using macros.
3 Replies
- محمد صالحCopper ContributorLoop for repeating with unknown times
For for repeating with exactly known times (30 times for example) - Haytham AmairahSilver Contributor
VB loop structures definition as Microsoft Developer Network:
The technique that allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is True, until a condition is False, a specified number of times, or once for each element in a collection.
To learn more about VB loop structures, just follow this link:
https://msdn.microsoft.com/en-us/library/ezk76t25.aspx
My own example about loop:
This is the code if you want to test it:
Sub Loop_Example() Do Until IsEmpty(ActiveCell) If ActiveCell.Value = 2 Then ActiveCell.Interior.Color = vbGreen ActiveCell.Offset(1, 0).Range("A1").Select Else 'Step down to the next row ActiveCell.Offset(1, 0).Range("A1").Select End If Loop End Sub- Satyendra BelwanshiCopper ContributorThanks Haytham