Auto cell numbering

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi Again,

Is there an easy way that I can auto number column A if there are entries in column B? Say I have 5 entries in column B , column A will auto number it from 1 to 5. I believe I saw this code before in this forum, I have been searching for it for about an hour now but to no avail. If anyone has it please help....


thanks,

splucena
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub test()
Dim LR As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
With Range("A1:A" & LR)
    .Formula = "=ROW()"
    .Value = .Value
End With
End Sub
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
Hi Again,

Is there an easy way that I can auto number column A if there are entries in column B? Say I have 5 entries in column B , column A will auto number it from 1 to 5. I believe I saw this code before in this forum, I have been searching for it for about an hour now but to no avail. If anyone has it please help....


thanks,

splucena
Maybe you are looking for a code solution, but manually (assuming no gaps in the column B data) you could ...

1. Enter the first two numbers (1 and 2)

2. Select those two cells and double click the Fill Handle (the little black square at the bottom right of the selection)
 
Upvote 0

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
Or this in A1 and copied down. Depends what you want.

=IF(LEN(B1)=0,0,SUMPRODUCT(--(LEN(B$1:B1)>0)))
 
Upvote 0

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi Friends,

Thanks for the quick reply and formulas. VoG's code is what suites my project. Thanks again to all of you!!!!!!

splucena
 
Upvote 0

SPLUCENA

Board Regular
Joined
Feb 24, 2009
Messages
189
Hi Vog,

I forgot to mention that my data entry on column B starts at row 13 and ends at row 25 (this actually is an invoice). I tried to modify your code to start at row 13 but what it is giving me is number 13 itself and not 1. Please assist.


thanks,

splucena
 
Upvote 0

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub test()
Dim LR As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
With Range("A13:A" & LR)
    .Formula = "=ROW()-12"
    .Value = .Value
End With
End Sub
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
Or maybe this?

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> AutoNumber()<br>    <SPAN style="color:#00007F">With</SPAN> Range("B13", Range("B" & Rows.Count).End(xlUp)).Offset(, -1)<br>        .Resize(1).Value = 1<br>        .DataSeries Type:=xlLinear, Step:=1, Trend:=<SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,190,953
Messages
5,983,819
Members
439,862
Latest member
FaisalAlTawil

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