I have the following pieces of code
which I have cobbled together with recorded macros and bits from here. I'm trying to go from this (one column)
NAME
Tom
****
Harry
to (2 columns)
# NAME
1 Tom
2 ****
3 Harry
with a varying range (sometimes it's 3 lines, sometimes it's 12 lines...).
The problem I'm having is that right now it adds 2 extra numbers at the bottom (only 1 if I just run those two pieces - strange - but I don't want ANY extras...). Why?
Am I using the LastRow function incorrectly? It seems like it will be very useful in creating the semi-idiot proof macro I'm working on now, but I think I'm missing something. Offsets maybe?
Code:
'Inserts new column before A
Range("A:A").Select
Selection.Insert Shift:=xlToRight
'Fills down to last row with record number
Range("A2").Select
ActiveCell.FormulaR1C1 = "1"
Range("A3").Select
ActiveCell.FormulaR1C1 = "2"
Range("A2:A3").Select
LastRow = Range("B" & Rows.Count).End(xlUp).Row
Selection.AutoFill Destination:=Range("A2").Resize(LastRow), Type:=xlFillDefault
which I have cobbled together with recorded macros and bits from here. I'm trying to go from this (one column)
NAME
Tom
****
Harry
to (2 columns)
# NAME
1 Tom
2 ****
3 Harry
with a varying range (sometimes it's 3 lines, sometimes it's 12 lines...).
The problem I'm having is that right now it adds 2 extra numbers at the bottom (only 1 if I just run those two pieces - strange - but I don't want ANY extras...). Why?
Am I using the LastRow function incorrectly? It seems like it will be very useful in creating the semi-idiot proof macro I'm working on now, but I think I'm missing something. Offsets maybe?