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: Working with Record Numbers.

# Working with Record Numbers

by Allen Wyatt
(last updated July 5, 2021)

For some data tables in Excel, you may want to assign a record number to cells in a particular column. For instance, you might want record numbers for 20 different records, ranging between 1 and 20 or between 100 and 119. It doesn't really matter to Excel what range you select. How you go about setting up the record numbers depends on what you want to later do with them.

If you want the record numbers to be static—that is, they are always assigned to a particular record and never change—then you should use the AutoFill feature of Excel to assign the numbers. To do this, simply enter all your data except the record numbers. Then type in the first two or three record numbers, select them, and drag on the AutoFill handle (the black square at the bottom-right corner of the selection) to fill out the rest of the records.

Using this approach is fast and easy, but it does make the record numbers static. For instance, if you delete the record that has a record number of 107, then that particular record number is gone, and your numbers will show a gap, jumping from 106 to 108.

If you want dynamic record numbers—ones that change as you make deletions—then you can use a formula to calculate the record numbers. You could put the first record number in, for instance, cell A5, and then in the next cell down you would use a formula such as =A5+1 to calculate the new record number.

This still presents a problem, however, because if you delete a record, all the record numbers below the one you deleted will show an error (#REF!). Why? Because you delete a cell on which the next cell down was dependent. A better solution is to use a record number formula that is dependent on the row in which the formula is located. For instance, let's assume your first record is in row 5. You could use this formula to generate a range of record numbers starting with 100:

```=ROW()+95
```

Now, if you delete a record, the remaining record numbers readjust themselves and you don't end up with any errors.

If you use this approach, you'll want to make sure that you don't delete any rows above those rows that contain your records, as doing so will cause your record numbers to be incorrect. For instance, if you use the above formula and you delete row 3, your first row for records becomes row 4, so your first record number becomes 99. (Remember that you wanted them to start with 100, so this is now incorrect!)

To head off this potential error, change your first formula (in cell A5) to the following:

```=ROWS(\$A\$4:\$A5)+98
```

Note that this formula doesn't use the ROW function, but the ROWS function. The ROWS function returns the number of rows in the range specified. In this case, it returns the value 2, which is added to 98, giving the desired record number of 100. Plus, if you delete any rows before row 4, your formula still works. You can copy the formula from A5 down as far as necessary, and you should end up with the proper record numbers in all the cells.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12402) 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: Working with Record Numbers.

##### 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

Errors when Copying References to External Cells

If you copy a cell that contains a reference to external data, do you get an error? It could be due to the complexity of ...

Discover More

Heavy-Duty Footnotes

Word allows you to add footnotes to a document, but they are rather straightforward and simple in their application. If ...

Discover More

Limiting a Calculated Value to a Range

If you want to limit what is returned by a formula to something between lower and upper boundaries, the solution is to ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

##### More ExcelTips (ribbon)

Monitoring the Number of Formats Defined

The number of formats used in a workbook can become a problem if you run up against the limit Microsoft hard-coded into ...

Discover More

Spotty Recalculation

Does your worksheet or workbook not always recalculate like you expect? If so, then some of the ideas in this tip may ...

Discover More

Making Pane Settings Persist

When you freeze panes in a worksheet, those panes should persist even though you save the workbook and reload it. There ...

Discover More
##### Subscribe

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

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 four less than 7?

2021-05-28 05:48:00

John Mann

Clarifying Bernard's comment.
You have to double-click the fill handle, not the selected range. It appears to only work if there is range of data in an adjacent column, which doesn't need to be formated as a table.
Double-clicking the fill handle doesn't appear to work for filling along a row.
Tests done in Excel 2010

2017-07-13 10:20:19

Allen Windhorn

Henk -- Thanks for the correction -- should have cut and pasted.

2017-07-12 08:09:03

Bernard

you don't need to drag the autofill handle, a doubleclick fills the entire range

2017-07-11 04:10:59

Henk

@Allen Windhorn: There is a mistake in your formula.

I tried the following (based on your reasoning) and it worked:
=MAX(INDIRECT("\$A\$5" & ":" &"A" & ROW()-1))+1

2017-07-10 10:04:06

Allen Windhorn

Another way is e.g. =MAX(INDIRECT(\$A\$5:\$A" & TEXT(ROW()-1,"0")))

With this you can insert blank or comment rows (non-numeric first column), or rearrange the order of rows, and the numbering will stay sequential. A5 should contain zero (or one less than first number)and should not be moved.

2017-07-09 14:26:02

Anne

The ROW or ROWS might work but another easy solution is to use OFFSET as in =OFFSET(A2,-1,0)+1 where A2 is the current cell. This adds 1 to whatever cell is currently above the active cell.

##### 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.