Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop to fill numbers in cells with VBA
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Format cells in a range with bold font and yellow background color Qomplainerz 0 772 07-27-2023, 11:26 AM
Last Post: Qomplainerz
  Autofill a series of numbers in a column Qomplainerz 0 388 07-27-2023, 11:23 AM
Last Post: Qomplainerz
  Loop through columns and clear contents Qomplainerz 0 395 07-27-2023, 11:21 AM
Last Post: Qomplainerz
  Split text in cells with VBA Qomplainerz 0 413 07-27-2023, 11:09 AM
Last Post: Qomplainerz
  Count colored cells with VBA Qomplainerz 0 356 07-27-2023, 11:07 AM
Last Post: Qomplainerz
  Generate random numbers in VBA Qomplainerz 0 414 07-27-2023, 11:03 AM
Last Post: Qomplainerz
  Calculate the avg and color the cells when their values are above or below the avg Qomplainerz 0 427 07-27-2023, 10:41 AM
Last Post: Qomplainerz
  Protect specific cells with VBA Qomplainerz 0 379 07-27-2023, 10:39 AM
Last Post: Qomplainerz
  Loop through worksheets and print their names in the immediate window Qomplainerz 0 406 07-27-2023, 09:42 AM
Last Post: Qomplainerz
  Insert a new row and fill it with data in VBA Qomplainerz 0 347 07-27-2023, 09:11 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 8 Guest(s)