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

[TABLE="width: 256"]


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

[TD="width: 64, bgcolor: transparent"]Column A[/TD]

[TD="width: 64, bgcolor: transparent"]Column B[/TD]

[TD="width: 64, bgcolor: transparent"]Column C[/TD]

[TD="width: 64, bgcolor: transparent"]Column D[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]RG4500[/TD]

[TD="bgcolor: transparent, align: right"]1.2[/TD]

[TD="bgcolor: transparent"]Phase 3[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]CIV550[/TD]

[TD="bgcolor: transparent, align: right"]33.3[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]RG4400[/TD]

[TD="bgcolor: transparent, align: right"]6.1[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]CV990[/TD]

[TD="bgcolor: transparent, align: right"]0[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]DC20122[/TD]

[TD="bgcolor: transparent, align: right"]6[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]CV990[/TD]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]CIV550[/TD]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]RG4500[/TD]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"][/TD]

[/TR]


</tbody>[/TABLE]

to


[TABLE="width: 256"]


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

[TD="width: 64, bgcolor: transparent"]Column A[/TD]

[TD="width: 64, bgcolor: transparent"]Column B[/TD]

[TD="width: 64, bgcolor: transparent"]Column C[/TD]

[TD="width: 64, bgcolor: transparent"]Column D[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]1[/TD]

[TD="bgcolor: transparent"]RG4500[/TD]

[TD="bgcolor: transparent, align: right"]1.2[/TD]

[TD="bgcolor: transparent"]Phase 3[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]2[/TD]

[TD="bgcolor: transparent"]CIV550[/TD]

[TD="bgcolor: transparent, align: right"]33.3[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]3[/TD]

[TD="bgcolor: transparent"]RG4400[/TD]

[TD="bgcolor: transparent, align: right"]6.1[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]4[/TD]

[TD="bgcolor: transparent"]CV990[/TD]

[TD="bgcolor: transparent, align: right"]0[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]5[/TD]

[TD="bgcolor: transparent"]DC20122[/TD]

[TD="bgcolor: transparent, align: right"]6[/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]6[/TD]

[TD="bgcolor: transparent"]CV990[/TD]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]7[/TD]

[TD="bgcolor: transparent"]CIV550[/TD]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"]Phase 2[/TD]

[/TR]

[TR]

[TD="bgcolor: transparent, align: right"]8[/TD]

[TD="bgcolor: transparent"]RG4500[/TD]

[TD="bgcolor: transparent"][/TD]

[TD="bgcolor: transparent"][/TD]

[/TR]


</tbody>[/TABLE]
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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,225,732
Messages
6,186,704
Members
453,369
Latest member
positivemind

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