DATA RECOVERY UNION > Articles > Vba – Filling cells with sequential numbers in an Excel (2003) macro
Posted in

Vba – Filling cells with sequential numbers in an Excel (2003) macro

I need to fill an excel column with a sequential series, in this case from -500 to 1000.  I’ve got a macro to do it, but it takes a lot of lines for something that seems like it should be a single function [something like FillRange(A2:A1502, -500, 1000, 1)].  But if that function exists, I can’t find it.  Is the following as simple and elegant as it gets?

'Draw X axis scaleCells(1, 1).Value = "mV"Cells(2, 1).Value = -500Cells(3, 1).Value = -499Cells(4, 1).Value = -498Dim selection1 As Range, selection2 As RangeSet selection1 = Sheet1.Range("A2:A4")Set selection2 = Sheet1.Range("A2:A1502")selection1.AutoFill Destination:=selection2

Solution:

Range("A1")=-500Range("A1").SelectSelection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _        Step:=1, Stop:=500, Trend:=False
💠

🔵 Best-selling hard drives, USB flash drives & SSDs everyone's buying.

Fast, reliable, and on sale now. Thousands pick these weekly — don't miss Amazon's lowest storage prices.

Top 10 Bestsellers
🏆 4.7★+ Reviews
📦 Prime Shipping
👉 See today's best-selling Data storage on Amazon.com HDD · USB Flash Drives · SSD · External Drives
🛒
✅ Updated hourly — Amazon real-time ranking 🔥 Limited stock deals 🔗 Affiliate
⭐ Click to see complete best-selling list ⭐