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

Posted by Fred Hamilton on Super User See other posts from Super User or by Fred Hamilton
Published on 2010-02-27T00:58:48Z Indexed on 2010/03/26 16:23 UTC
Read the original article Hit count: 256

Filed under:
|
|

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

© Super User or respective owner

Related posts about excel-vba

Related posts about vba