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 scale
Cells(1, 1).Value = "mV"
Cells(2, 1).Value = -500
Cells(3, 1).Value = -499
Cells(4, 1).Value = -498
Dim selection1 As Range, selection2 As Range
Set selection1 = Sheet1.Range("A2:A4")
Set selection2 = Sheet1.Range("A2:A1502")
selection1.AutoFill Destination:=selection2
Range("A1")=-500
Range("A1").Select
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Stop:=500, Trend:=False
Sub FillASeries()
With Sheet1.Range("a1")
.Value = -500
.AutoFill .Resize(1501, 1), xlFillSeries
End With
End Sub
I don't think there's a single function, but this is as short as I can make the procedure.
What you're looking for is not a function.
Type -500 in A2 and type "Ctrl+Enter" (That accepts the number and selects the cell)
Then go to the "Edit" Menu --> "Fill" --> "Series"
Set the "Series in" to "Columns"
Set the "Stop Value" to 1000
Hit "OK" and you'll have the result you want.