Adjusting Formulas for Top-Added Rows

Written by Allen Wyatt (last updated January 25, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


5

Bill has a formula that sums a column in rows 2 through 15, using the SUM function. If he adds a row anywhere at rows 3 through 15, the formula adjusts properly. If he adds a row at the top (just above row 2), the formula does not adjust at all to include the inserted row. Bill wonders if there is a way to make the formula adjust properly and automatically when he adds a row at the top of what is being summed.

There are many schools of thought on how this can be done, each implementing a different technique to accomplish the same thing. One approach is to simply convert your data into a formal table in the worksheet. The easiest way is to select a cell within your data and then press Ctrl+T. Excel recognizes your data as a table and if you insert any rows at the top of your table, just under your headings, they are automatically reflected in the summing of the table.

Another approach is to adjust your SUM formula. You proabably are doing a sum of rows 2 through 15 because row 1 has a column heading in it. If this is the case (and if the column heading contains text), then simply adjust your SUM formula so it references rows 1 through 15. Now, when someone adds a new row at row 2, it is automatically included in the sum. Further, the text in the column heading won't affect that sum in the least.

If your headings contain numbers that may actually mess up your sums, then you can try a variation. Insert a blank row at row 2 and adjust your SUM formula so it references rows 2 through 16. (It will be row 16 instead of 15 because you added the new, blank row 2.) Then, hide row 2 so it isn't visible. Now when people add rows at the top, they will actually be adding them at row 3 and the SUM formula will still reference the hidden row 2—adjustments will occur correctly.

You could also use an approach where you adjust the SUM formula to use either the INDIRECT or OFFSET function. Assume, for a moment, that your current SUM formula looks like this:

=SUM(A2:A15)

Change it so that it looks like one of the following:

=SUM(INDIRECT("A2"):A15)
=SUM(OFFSET(A1,1,0):A15)

Both of these formulas "anchor" the top cell of the range. When you insert cells at the top of the summed range (before row 2), Excel won't adjust the cell references in either the INDIRECT function or in the OFFSET function. The result is that your SUM formula will always reference the top range cell you want.

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

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

Discovering the RGB Value of a Custom Text Color

Word allows you to easily change the color of the text in your document. If you get a document from someone else, you may ...

Discover More

Clearing Everything Except Formulas

Need to get rid of everything in a worksheet except for your formulas? You can do it rather easily by applying the ideas ...

Discover More

Creating a Shape

Ever wanted to create a simple drawing in your worksheet? Excel has made this simple. This tip explains how Excel uses ...

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)

Determining a State from an Area Code

Want to be able to take information that is in one cell and match it to data that is contained in a table within a ...

Discover More

Deriving High and Low Non-Zero Values

When analyzing your numeric data, you may need to figure out the largest and smallest numbers in a set of values. If you ...

Discover More

Getting a Conditional Count of Cells Containing Values

Excel provides several worksheet functions that can be used to count cells containing values--"particularly numeric ...

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 two more than 9?

2021-09-09 13:01:44

Michael F

I've been using the offset method for years but recently learned it's volatile and can drastically slow down the calculation performance of your sheet (any change on your sheet recalculates ALL the offset formulas, regardless if they are impacted by the change). A few offsets won't matter but if you have an estimate that is a few thousand lines with subtotal rows using this offset method, it can really impact the sheet performance. Is there any way to anchor the bottom (or top) cell using index (or another non-volatile) function?


2021-06-03 10:36:15

Dave

Idorenyin:

I think my example from 2020-05-24 (below) handles your request.


2021-06-02 16:17:48

Idorenyin

=SUM(INDIRECT("A2"):A15)

Please help me with a reverse of the above formula that "anchor" the bottom cell of the range. When you insert cells at the bottom of the summed range. Thanks.


2021-04-07 09:38:46

Farid

Hello Sir
Good day to you
Is it possible to do any formula or just we can do SUM some rows?
When rows adding in top of page and some of columns have formula like this
=((A2*B2/3) *(A2+C2))
Can can I do this formula automatically when the new row will add from top?
thanks in advance


2020-05-24 12:12:04

Dave

Allen presented two formulaic options:
= SUM( INDIRECT( "A2" ):A15 )
= SUM( OFFSET( A1, 1, 0 ):A15 )
I greatly prefer the second option. Why? because it is robust and needs no further adjustment if you ever add a new row before row 1.
In addition, being old school, I am partial to using a footer row the end my data. I usually color it the same as the title row and add some text such as "Insert all new rows above this row".
Following Allen's example, I would add the footer row as row 16. Then the formula becomes:
= SUM( OFFSET( A1, 1, 0 ):OFFSET( A16, -1, 0 ))
You'll notice I include spaces in my formulas to make them more readable. It's easy and it takes up very little memory. I don't understand why more people don't. After all, Wedon'twritesentenceslikethis.


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.