Auto numbering

k0915

New Member
Joined
Jan 7, 2014
Messages
3
I would like to have auto-numbering after inserting new row, required that the new row has input any text.

here is the example:

Item no. name
1    Mary
2    Tom
3    Jack
4    Peter
5    John

When I insert new row, I would like to have the row no. only when the column "name" has some text inside, otherwise the auto-numbering will skip the blank row.

Item no. name
1    Mary
2    Tom

3    Jack
4    Peter
5    John

Item no. name
1    Mary
2    Tom
3    Susan
4    Jack
5    Peter
6    John

Would there be any code to do this?
Thank you very much!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

dermie_72

Well-known Member
Joined
Sep 4, 2012
Messages
1,540
Assumming your numbers are in Column A, starting in Row 1, instead of putting 2 below the 1, put = A1+1.
Then drag that formula down. (or click back on the cell, then double click the bottom right hand corner of the active cell)
When you add a row. Click on the empty spot and press (control + D), and it should repopulate the numbers to the correct order.
 

k0915

New Member
Joined
Jan 7, 2014
Messages
3
Thanks for your reply.

However, I would like to have the row number appears automatically only if i put some text in the cell under the column "name" of the row, and if possible, I would like to have it automatically instead of repopulate the numbers by any steps.
 

k0915

New Member
Joined
Jan 7, 2014
Messages
3

ADVERTISEMENT

Could you please explain more on how to write the marco?

Thanks
 

PaddyD

MrExcel MVP
Joined
May 1, 2002
Messages
14,234
If you don't mind doing a bit of work, a formula will suffice for the basic calculation:

=IF(LEN(B2),COUNTA($B$2:B2),"")

...you'll just need to copy it into the new row(s) you insert.
 

dermie_72

Well-known Member
Joined
Sep 4, 2012
Messages
1,540
Nice one Paddy. K0915 was wanting it to autopopulate when a row was inserted. While your formula would produce a similar result, it would still require the formula to be copied down after the insert...or have I got it wrong?

K0915, if you go to the links that I provided it should explain how to write the macro. If you're not proficient in writing macros, I highly recommend using either Paddy's or My formula and copying it down when you insert a new row.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,750
Messages
5,638,138
Members
417,010
Latest member
jnuss03

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