Autofill a series of numbers in a column - 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: Autofill a series of numbers in a column (/showthread.php?tid=5270) |
Autofill a series of numbers in a column - Qomplainerz - 07-27-2023 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. |