QP School

Full Version: Loop to fill numbers in cells with VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Example:

Sub FillNumbersInCells()
    Dim i As Integer
   
    For i = 1 To 10
        Range("A" & i).Value = i
    Next i
End Sub

Explanation:

The code defines a subroutine named FillNumbersInCells.
It declares a variable i to be used as a loop counter.
The For loop is used to repeat the following actions from i = 1 to i = 10.
In each iteration of the loop, the Range("A" & i).Value statement sets the value of cell A1 to A10 to the value of i, which is the loop counter.