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 781 07-27-2023, 11:26 AM
Last Post: Qomplainerz
  Autofill a series of numbers in a column Qomplainerz 0 400 07-27-2023, 11:23 AM
Last Post: Qomplainerz
  Loop through columns and clear contents Qomplainerz 0 405 07-27-2023, 11:21 AM
Last Post: Qomplainerz
  Split text in cells with VBA Qomplainerz 0 419 07-27-2023, 11:09 AM
Last Post: Qomplainerz
  Count colored cells with VBA Qomplainerz 0 364 07-27-2023, 11:07 AM
Last Post: Qomplainerz
  Generate random numbers in VBA Qomplainerz 0 424 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 442 07-27-2023, 10:41 AM
Last Post: Qomplainerz
  Protect specific cells with VBA Qomplainerz 0 386 07-27-2023, 10:39 AM
Last Post: Qomplainerz
  Loop through worksheets and print their names in the immediate window Qomplainerz 0 419 07-27-2023, 09:42 AM
Last Post: Qomplainerz
  Insert a new row and fill it with data in VBA Qomplainerz 0 351 07-27-2023, 09:11 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 2 Guest(s)