VBA 6 Loops - For, Do-While and Do-Until Loops
VBA 6 Loops - For, Do-While and Do-Until Loops
ExcelFunctions.net
Search Site:
Custom Search
n Excel
The Visual Basic For Loop
The Visual Basic 'For' loop takes on two separate forms.
These are the For ... Next loop and the For Each loop.
cel Errors
The above simple For ... Next loop sets the variable i to
have the values 1, 2, 3, ..., 10, and for each of these
https://www.excelfunctions.net/vba-loops.html 1/6
3/9/2020 VBA Loops - For, Do-While and Do-Until Loops
You can also use negative step sizes in the VBA For
loop, as is illustrated below:
For i = 10 To 1 Step -1
iArray(i) = i
Next i
https://www.excelfunctions.net/vba-loops.html 2/6
3/9/2020 VBA Loops - For, Do-While and Do-Until Loops
For i = 1 To 100
If dValues(i) = dVal Then
indexVal = i
Exit For
End If
Next i
' Sub procedure to list the Fibonacci series for all values
below 1,000
Sub Fibonacci()
https://www.excelfunctions.net/vba-loops.html 3/6
3/9/2020 VBA Loops - For, Do-While and Do-Until Loops
End Sub
https://www.excelfunctions.net/vba-loops.html 4/6
3/9/2020 VBA Loops - For, Do-While and Do-Until Loops
Do
.
.
.
Loop While iFib_Next < 1000
iRow = 1
Do Until IsEmpty(Cells(iRow, 1))
' Store the current cell value in the dCellValues array
dCellValues(iRow) = Cells(iRow, 1).Value
iRow = iRow + 1
Loop
https://www.excelfunctions.net/vba-loops.html 5/6
3/9/2020 VBA Loops - For, Do-While and Do-Until Loops
Do
.
.
.
Loop Until IsEmpty(Cells(iRow, 1))
https://www.excelfunctions.net/vba-loops.html 6/6