Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Autofill a series of numbers in a column
#1
Example:

Sub AutofillSeries()
    Dim ws As Worksheet
    Dim startValue As Integer
    Dim endValue As Integer

    'Set the worksheet where the series will be created
    Set ws = ThisWorkbook.Sheets("Sheet1")

    'Specify the start and end values for the series
    startValue = 1
    endValue = 10

    'Enter the start value in the first cell of the series (A1)
    ws.Range("A1").Value = startValue

    'Autofill the series from the second cell (A2) to the end value (A10)
    ws.Range("A1").AutoFill Destination:=ws.Range("A1:A10"), Type:=xlFillSeries
End Sub

Explanation:

The code defines a subroutine named AutofillSeries.
It declares variables for the worksheet (ws), the start value of the series (startValue), and the end value of the series (endValue).
Set ws = ThisWorkbook.Sheets("Sheet1") specifies the worksheet ("Sheet1") where the series will be created.
startValue = 1 and endValue = 10 set the start and end values for the series.
The start value (1 in this example) is entered in cell A1 using ws.Range("A1").Value = startValue.
The ws.Range("A1").AutoFill method is used to autofill the series from cell A2 to cell A10. 
Destination:=ws.Range("A1:A10") specifies the destination range for autofilling, and Type:=xlFillSeries indicates that it should be filled as a series.
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
  Generate random numbers in VBA Qomplainerz 0 424 07-27-2023, 11:03 AM
Last Post: Qomplainerz
  Calculate the sum of values in a column with VBA Qomplainerz 0 364 07-27-2023, 08:18 AM
Last Post: Qomplainerz
  Loop to fill numbers in cells with VBA Qomplainerz 0 388 07-27-2023, 08:16 AM
Last Post: Qomplainerz
  Calculate the average of three numbers in VBA Qomplainerz 0 333 07-27-2023, 07:40 AM
Last Post: Qomplainerz
  Loop to display numbers in VBA Qomplainerz 0 339 07-27-2023, 07:33 AM
Last Post: Qomplainerz
  Floating-point numbers with double precision in VBA Qomplainerz 0 307 07-26-2023, 08:23 PM
Last Post: Qomplainerz
  Floating-point numbers with single precision in VBA Qomplainerz 0 276 07-26-2023, 08:23 PM
Last Post: Qomplainerz
  How to format an entire column as number without thousand separator in Excel VBA Qomplainerz 0 464 04-13-2023, 12:26 PM
Last Post: Qomplainerz
  How to format an entire column as number with thousand separator in Excel VBA Qomplainerz 0 438 04-13-2023, 12:25 PM
Last Post: Qomplainerz
  How to select an entire column in Excel VBA Qomplainerz 0 403 04-13-2023, 12:03 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 3 Guest(s)