Fill a Numeric Series to a Target Value with an Excel VBA Macro
Question details
Create an Excel VBA macro that fills a numeric series using start and stop values stored in worksheet cells.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user wants to select an output cell and generate a series in increments of 100 between two cell values.
- Observed behavior
- The series should run upward or downward from the start value without passing the stop value, with the option to change which cell contains the stop value.
Use a desktop version of Excel that supports VBA, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Choose an empty output column with enough space below the starting cell; the macro will overwrite cells in its output range.
Create a VBA macro that fills a series in steps of 100
Use this macro when the start and stop values are in worksheet cells and you want to choose where the series begins.
The macro reads A1 as the start value and A2 as the stop value on the active worksheet. It fills downward from the active cell, increasing or decreasing by 100 as needed.
If the difference between the values is not divisible by 100, the final entry is the last value before the stop value; the macro does not add an irregular final step.
On the worksheet, enter the numeric start value in A1 and the numeric stop value in A2. Leave the intended output cells empty and separate from these input cells.
Open Developer > Visual Basic, choose Insert > Module, and paste this code: Sub StartFilling() Dim ws As Worksheet Dim dest As Range Dim startValue As Double, stopValue As Double Dim increment As Double, count As Double Dim i As Long Set ws = ActiveSheet Set dest = ActiveCell If Not IsNumeric(ws.Range("A1").Value2) Or Not IsNumeric(ws.Range("A2").Value2) Then MsgBox "Enter numeric start and stop values in A1 and A2." Exit Sub End If startValue = CDbl(ws.Range("A1").Value2) stopValue = CDbl(ws.Range("A2").Value2) increment = 100 If stopValue < startValue Then increment = -100 count = Fix(Abs(stopValue - startValue) / 100) + 1 If count > ws.Rows.Count - dest.Row + 1 Then MsgBox "There are not enough rows below the selected cell." Exit Sub End If For i = 0 To CLng(count) - 1 dest.Offset(i, 0).Value2 = startValue + i * increment Next i End Sub
Return to the worksheet and click the empty cell where the first series value should appear. The macro writes downward from that cell.
Choose Developer > Macros, select StartFilling, and click Run. Enable macros if Excel prompts you and you trust the workbook.
If the stop value is in B1 instead of A2, open Developer > Visual Basic and replace both occurrences of ws.Range("A2") in the code with ws.Range("B1"). Also update the message text so it identifies B1.

Work with Numeric Series in WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and Microsoft Excel format compatibility for an easy transition. WPS Spreadsheet can help you create and edit numeric series, although it does not fix an Excel VBA macro; VBA support depends on the WPS edition.

Frequently Asked Questions
Can the macro use B1 for the stop value?
Yes. In Developer > Visual Basic, replace both occurrences of ws.Range("A2") with ws.Range("B1"), and update the message text to match.
What happens if the start value is greater than the stop value?
The macro fills downward in the worksheet while decreasing the numeric values by 100 each time. It stops before a value would pass the lower limit.
Will the series always include the stop value?
Only if the difference between the start and stop values is divisible by 100. Otherwise, the macro stops at the last 100-step value before the limit.
Why can't I save the macro in an XLSX file?
The XLSX format cannot retain VBA code. Use File > Save As and select Excel Macro-Enabled Workbook (.xlsm) to keep the macro.
Can I fill a series without a macro?
In Excel, enter the first value, select the intended output range, and use Home > Fill > Series. Choose a linear series, enter a step value such as 100 or -100, and provide a stop value.




