Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Written by Allen Wyatt (last updated June 4, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


2

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.

The need that Libby has expressed precludes using any static numbering scheme in column A. Since she wants the row numbers to update automatically if she adds or deletes rows, then a formula is needed. 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, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Creating a Boilerplate Document

If you have several boilerplate documents you need to routinely use in Word, then you should learn how to use templates. ...

Discover More

Changing Print Dialog Box Defaults

Some of the built-in defaults in Word can't be changed. Often times, however, you can work around these defaults by using ...

Discover More

End-of-Month Calculations

Don't want to use the EOMONTH function to figure out the end of a given month? Here are some other ideas for discovering ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Filling References to Another Workbook

When you create references to cells in other workbooks, Excel, by default, makes the references absolute. This makes it ...

Discover More

Counting Cells According to Case

Text placed in cells can either be lowercase, uppercase, or a mixture of the two. If you want to count the cells based ...

Discover More

Summing Cells Using a Particular Background Color

Do you need to total all the cells that are a particular color, such as yellow? This tip looks at three different ways ...

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}] (all 7 characters, in the sequence shown) 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 2 + 8?

2023-03-11 05:10:47

Barry

Putting your data into an Excel Table will automatically copy formulas down whenever a new row is added.


2023-03-10 10:52:04

Ron S

Here is another article that gives you formulas for several situations
https://exceljet.net/formulas/automatic-row-numbers

While you are there check out his "500 Formulas" link.


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.