# Adding a Statement Showing an Automatic Row Count

by Allen Wyatt
(last updated September 21, 2020)

Jithin has a data table that has 20 rows. He would like to add a statement below the table saying "This table has 20 rows." He would like to make the row count dynamic, however, as he frequently adds rows to or deletes rows from the table.

There are a number of ways you can put together such a statement, and the ways vary depending on how you put your data table together. If your data is simply that—data in an Excel worksheet—then you can use a formula similar to the following:

="The data table has " & COUNTA(A2:A21) & " rows"

This assumes that you table is in rows 1 through 21, with row 1 being a row of headings. (In other words, actual data is in rows 2 through 21.) The COUNTA function returns a count of any cells in the range A2:A21 that are not empty.

The only thing that you need to be careful of is when you add rows to your data table. In order for the formula to automatically adjust, you'll want to make sure that you only add rows after row 2 and before row 21. Doing anything different will mean that your "totals" formula points to the wrong rows.

Of course, you could modify the formula just a bit to overcome this potential problem. All you need to do is make sure that your "totals" formula is in row 23 (or in a row further down) and that your formula references rows 1 through 22:

="The data table has " & COUNTA(A1:A22) - 1 & " rows"

This works on the assumpution (again) that row 1 contains headings (thus the act of subtracting 1 from what COUNTA returns) and that row 22 is empty. Now you can add rows anywhere from rows 2 through 22 and you'll have no problem with the formula.

The above formulas work only if there are no blank cells in the range A1:A22. If there are, then a different approach would be better. This formula using the ROWS function will give the desired result:

="The data table has " & ROWS(A2:A21) & " rows"

There are other variations on these formulas that could be used, relying on other functions such as ROW, SUBTOTAL, COUNT, COUNTBLANK, and a few others. For general purposes, though, the examples already provided should work just fine.

There is another way your data can be formatted—as a formal "data table." This is done by selecting your data, displaying the Insert tab of the ribbon, and then clicking Table. Once the table is created, it is automatically assigned a name by Excel. The default name for your first table is Table1, then Table2, etc. Given this information, the easiest way to get your totals formula is like this:

="The data table has " & ROWS(Table1) & " rows"

The benefit to this approach is that you can insert rows anywhere within the defined table, and the ROWS function will always refer to the proper rows in the table.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2294) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

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

Synchronized Workbook and Worksheet Names

When you work on older workbooks in Excel, you may notice that the name of the worksheet tab and the workbook itself are ...

Discover More

How Word Applies Styles

Styles are a great boon for applying styles in a powerfully consistent manner. How Word applies styles, however, depends ...

Discover More

Getting a Double-Spaced Printout

When working with printed documents, many people prefer to see the document double-spaced. If you have a single-spaced ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

##### More ExcelTips (ribbon)

Generating Random Strings of Characters

If you need to generate a random sequence of characters, of a fixed length, then you'll appreciate the discussion in this ...

Discover More

Breaking Up Variable-Length Part Numbers

Part numbers can often be long, made up of other component elements. Breaking up part numbers into individual components ...

Discover More

Calculating an Expanding Square

When doing a systematic search for rescue purposes, it isn't unusual to implement what is termed an "expanding square." ...

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}] 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 seven more than 2?

2019-12-09 15:12:20

Alec Whatmough

This sort of scenario is a good example of why it can be a good idea to have your totals at the top of the sheet (even if it is just a row referencing another one at the bottom). Combine this with freezing panes means you can add, delete and scroll to your heart's content and the summary data is always right in front of your eyes.

2016-05-09 16:04:13

Where do you enter this formula in code to get it to apply to entire table?

2016-05-08 06:27:24

Willy Vanhaelen

If you want to exclude hidden rows from the calculation, you must use the SUBTOTAL function

2016-05-07 23:17:15

VB MUDGIL

I am an exeloholic. Today is my 1St day I am on this page or website. Really thrilled to learn new excel tips. The above was a good tip although I knew it before hand
Thanks
Vb Mudgil

2016-05-07 12:31:49

Jimbo

If you don't want to put the row count at the bottom of the rows, could you use
COUNTA(A:A)

2016-05-07 06:39:41

marlene

Really useful tips. I like the fact the info is clear therefore easy for a novice to understand. Added plus you give more than one option for the query.

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