Forum Discussion

3 Replies

  • Loop for repeating with unknown times

    For for repeating with exactly known times (30 times for example)
  • Haytham Amairah's avatar
    Haytham Amairah
    Silver 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

     

Resources