Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Automatically Numbering Rows.

Automatically Numbering Rows

by Allen Wyatt
(last updated January 30, 2016)

6

Libby wants to insert a row number into column A of her worksheet. She wants the column to reflect the correct number of the row, even when she adds or deletes rows.

There are any number of formulas you can use in column A that will return a row number. Perhaps the easiest is to use the ROW function, like this:

=ROW()

This formula returns the row number of the cell in which the formula appears. If you want to offset the row number returned (for instance, if you have some headers in rows 1 and 2 and you want cell A3 to return a row value of 1), then you can modify the formula to reflect the desired adjustment:

=ROW()-2

Of course, the ROW function isn't the only candidate for your formulas. You can also use a formula that actually examines the contents of the adjacent column (B) and return a row number only if there is something in that adjacent cell.

=IF(TRIM(B1)<>"",COUNTA($B$1:B1)&".","")

This formula, placed in cell A1, examines the contents of cell B1. If there is something there, then the COUNTA function is used to count the number of occupied cells between cell B1 and whatever cell is to the right of where this formula is placed. The formula also places a period after the row number that is returned. Make sure the dollar signs are included, as shown, and then copy the formula down as many cells as necessary to create your row numbers.

The advantage to a formula such as this one is that it checks to see if something is in column B before it returns a row number. This means that you can copy the formula down beyond the actual end of your data rows, and only those rows that have data (triggered by something in column B) will have a row number. The same sort of technique could be used with the ROW function instead of the COUNTA function:

=IF(TRIM(B1)<>"",ROW()&".","")

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10104) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Automatically Numbering Rows.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Refreshing PivotTable Data

If you modify the data on which a PivotTable is based, you'll need to refresh the table so it reflects the modified data. ...

Discover More

Problem with Menus Crashing Word

What do you do if, one day, one of your Word menus suddenly stops working and actually crashes the program? Here's the ...

Discover More

Making Text Bold

Want a cool shortcut to make your text bold? Here's a method that fits in wonderfully with how things are done in the ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Finding the Nth Occurrence of a Character

The FIND and SEARCH functions are great for finding the initial occurrence of a character in a text string, but what if ...

Discover More

Determining Combinations to Make a Total

If you have a range of cells that contain values, you may wonder which combinations of those cells should be used to meet ...

Discover More

Adjusting Formulas for Top-Added Rows

Formulas are the heart of using Excel, and formulas often refer to ranges of cells. How you insert cells into the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 0?

2017-10-03 02:18:38

MIchael Armstrong

....or, type a "1" in the top cell (assumed to be A1), then =A1+1 in A2, and fill/copy a2 to the end. Finally, value-copy that column to itself.


2017-10-02 09:39:27

MIchael Armstrong

I often sequence rows so I can return to the original order after sorting on other row(s). I assume row() will not work for this application?


2017-10-01 08:16:33

Ajit

My cell returns with wingdings if it confirms the parameters
Formula =IF(AND(E10>=1,F10=2),"a","")

Now that each such wingding needs to be counted with serial number in another cell

Like the one here; =IF(AND(O10>="a",F10=2),1,"") but it always return with 1 instead of 2 in the next row.

Kindly enlighten me on how to get the successive wingdings with successive numbers.

Thanks

Ajit Phape


2016-01-31 07:06:31

Michael (Micky) Avidan

To my opinion there is no need to declare a "Table"
* In the first cell type the first number (usually: 1).
* In the next cell (same column) type the following formula and copy down as far as needed.
=OFFSET(K6,-1,)+1
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-01-30 15:51:21

Phil

Saved me a lot of time. I can't tell you how many times I have used the Fill Cell and then formating the cell with a custom "0)" to add right ).


2016-01-30 08:04:53

Marcel Beugelsdijk

Depending on the requirements, I would either:

not use a formula, but type 1 and 2 in the first 2 cells, select both and drag down, 9or use the fill series functionality)

or

create a table (e.g. Table1) with formula in the first table data row:
=ROW()-ROW(Table1[#Headers])
which will still work when the table is moved, table rows are deleted or inserted.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.