Fill Series of Sequential Numbers in Column A Based on Last Value in Column B - VBA

CC268

Active Member
Joined
Mar 7, 2016
Messages
328
This should be fairly straight forward, but I am having a tough time getting it figured out. I simply want to insert a blank Column A and then fill in Column A with a series of sequential numbers all the way down until the last value in Column B.

Here is what I have so far...

Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Sub FillSeries()

    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

    'r = row, c = column
    Application.Goto Reference:="R1C2" 
    With Worksheets("Sheet1")
    LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
    .Range("B1:B" & LastRow).Select

    End With</code>

Cell B2 will always be blank so we need to make sure we are using the .End(xlUp).Row function to make sure the code isn't stopping at cell B2 and is capturing the entire range of Column B.

Unfortunately I can't use file sharing sites here at work, so I am unable to upload a sample. However, here is a photo to give you an idea of what I want done.

xVhLA3ETnhKkVYoi8
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Perhaps:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG24Jan13
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Lst = Range("B" & Rows.Count).End(xlUp).Row
[COLOR="Navy"]With[/COLOR] Range("A1")
    .Value = "1"
    .AutoFill Destination:=Range("A1").Resize(Lst), Type:=xlFillSeries
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Since you are starting at Row 1, you could also use this macro...
Code:
Sub SeriesFillColumnA()
  With Range("A1:A" & Cells(Rows.Count, "B").End(xlUp).Row)
    .Value = Evaluate("ROW(" & .Address & ")")
  End With
End Sub
 
Last edited:
Upvote 0
Hi MickG

A year and a half later and this is exactly the solution I needed!

Thanks!
 
Last edited:
Upvote 0
Since you are starting at Row 1, you could also use this macro...
Code:
Sub SeriesFillColumnA()
  With Range("A1:A" & Cells(Rows.Count, "B").End(xlUp).Row)
    .Value = Evaluate("ROW(" & .Address & ")")
  End With
End Sub

Since you are starting at Row 1, you could also use this macro...
Code:
Sub SeriesFillColumnA()
  With Range("A1:A" & Cells(Rows.Count, "B").End(xlUp).Row)
    .Value = Evaluate("ROW(" & .Address & ")")
  End With
End Sub
Since you are starting at Row 1, you could also use this macro...
Code:
Sub SeriesFillColumnA()
  With Range("A1:A" & Cells(Rows.Count, "B").End(xlUp).Row)
    .Value = Evaluate("ROW(" & .Address & ")")
  End With
End Sub

How different would the macros be if i was starting in row 2 (A2)?
I have tried changing the range from A1:A to A2:A - but the sequential numbers start at 2 instead of 1 in A2.
 
Upvote 0
I am not sure why you quoted my code three times but here is the code for starting at Row 2...
VBA Code:
Sub SeriesFillColumnA()
  With Range("A2:A" & Cells(Rows.Count, "B").End(xlUp).Row)
    .Value = Evaluate("ROW(" & .Address & ")-1")
  End With
End Sub
Note that what is being subtracted is one less than the start row number. If you started at Row 5, you would subtract 4. The reason there was no subtraction in my original code is when you start at Row 1, one less than that is zero and since subtracting zero does not change a value, it was omitted.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top