07-27-2023, 08:16 AM
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.
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.