Loop to fill numbers in cells with VBA - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Loop to fill numbers in cells with VBA (/showthread.php?tid=5245) |
Loop to fill numbers in cells with VBA - Qomplainerz - 07-27-2023 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. |