Add Serial Numbers in new column up to last row based on next column

VB_Gizmo2018

New Member
Joined
Jun 12, 2018
Messages
1
Dear Community,
I am returning back to VBA after a very long break and have managed to forgotten the code to run a macro that adds serial numbers on the left hand side of a blank column from start of the data up to the last row based on a column with last row data which can vary in legth

from

Column AColumn BColumn CColumn D
RG45001.2Phase 3
CIV55033.3Phase 2
RG44006.1Phase 2
CV9900Phase 2
DC201226Phase 2
CV990Phase 2
CIV550Phase 2
RG4500


<colgroup><col width="64" style="width: 48pt;" span="4">
<tbody>






















































</tbody>

to


Column AColumn BColumn CColumn D
1RG45001.2Phase 3
2CIV55033.3Phase 2
3RG44006.1Phase 2
4CV9900Phase 2
5DC201226Phase 2
6CV990Phase 2
7CIV550Phase 2
8RG4500


<colgroup><col width="64" style="width: 48pt;" span="4">
<tbody>






















































</tbody>
I remember I have to define lastrow variable based on say column B and run the sequence up to 8th row in above example but thats about it.

I didnt find anything similar in existing threads to created this thread
thanks in advance
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
try
Code:
Sub serialnum()
Dim lr As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
a = 1
For x = 2 To lr 'assumes row headers in row 1 and numbers should start in row 2
    Cells(x, 1) = a
    a = a + 1
Next x
End Sub
 
Upvote 0
Another option
Code:
Sub AddValues()
Range("A2").Value = 1
Range("A2").AutoFill Range("A2", Range("B" & Rows.Count).End(xlUp).Offset(, -1)), xlFillSeries
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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