Auto Numbering

vijay2482

Board Regular
Joined
Mar 3, 2009
Messages
142
i have a worksheet with few rows..
in column B i want to number the rows from 1 to n...

how to achieve this???

thanks in advance
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
ADVERTISEMENT
How far down do you want to number? To number column B until the last entry in column A:

Code:
Sub AutoNum()
 
Dim rngStart, rngC As Range
 
Set rngStart = Range(Cells(1, "B"), Cells(Cells(Rows.Count, "A").End(xlUp).Row, "B"))
 
Application.ScreenUpdating = False
 
For Each rngC In rngStart
    rngC.Value = rngC.Row
Next rngC
 
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0

vijay2482

Board Regular
Joined
Mar 3, 2009
Messages
142
thanks...
your code works fine...
it enters the number of the row...

i want the numbers from 1 to n to be entered in column B starting from row 4

i did a small modification to ur code and got the result in column B line number starting from 4...

i want it to start at 1 in column B row 4

Code:
Sub AutoNum()
Dim rngStart, rngC As Range
Set rngStart = Range(Cells(4, "B"), Cells(Cells(Rows.Count, "A").End(xlUp).row, "B"))
Application.ScreenUpdating = False
For Each rngC In rngStart
    rngC.Value = rngC.row
Next rngC
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
Rich (BB code):
Sub AutoNum()
Dim rngStart, rngC As Range
Set rngStart = Range(Cells(4, "B"), Cells(Cells(Rows.Count, "A").End(xlUp).row, "B"))
Application.ScreenUpdating = False
For Each rngC In rngStart
    rngC.Value = rngC.row-3
Next rngC
Application.ScreenUpdating = True
End Sub
 
Upvote 0

vijay2482

Board Regular
Joined
Mar 3, 2009
Messages
142
thanks a lot..............

that works perfect..
u r a genious

thank you once again for helping...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,195,943
Messages
6,012,431
Members
441,700
Latest member
Warbo

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
Top