Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Finding the Sum of a Sequential Integer Range.

Finding the Sum of a Sequential Integer Range

Written by Allen Wyatt (last updated August 20, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


8

Excel includes the FACT worksheet function which returns the factorial of a value. (The factorial of the number X is the result of multiplying 1 * 2 * 3 ... * X.) Sabeesh wonders if there is a similar function that will return the sum of the values (1 + 2 + 3 ... + X) instead of the result of the values.

There is no such function built into Excel, but a quick mathematical formula will do the trick. The proper terminology to refer to this type of sum is a "triangular number." This derives from the fact that if the sum was represented with objects, they could always be arranged in the form of a triangle. For example, if you had 5 objects on the bottom row, 4 on the next, 3 three on the third, 2 on the fourth, and 1 on the top row, you have a triangle. Summing the number of objects (5 + 4 + 3 + 2 + 1) is what Sabeesh wants to do.

The answer to this problem can be expressed as a mathematical formula, reportedly discovered by Carl Friedrich Gauss. (Which is the source for another name of this type of number: a Gaussian Summation.) Note that the sum of opposite rows in the above example are always the same: 5 + 1 is the same as 4 + 2. This is true regardless of the number of rows; if there were 100 rows, then 100 +1 is the same result as 99 + 2, 98 + 3, 97 + 4, etc. What you end up with is 50 "pairs" of numbers equal to 1 more than the upper limit of your range.

The upshot of all this—without going through a lot of explanation—is that you can find the triangular number for any positive value (where you start at 1 and end with X) in the following manner:

=X*(X+1)/2

Thus, if you had a number in cell A1 and you wanted to know the sum of the range of 1 through that number, you could use this formula:

=A1*(A1+1)/2

This formula provides a simple way to determine the sum required, without the necessity of resorting to using a macro.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9997) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Finding the Sum of a Sequential Integer Range.

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

Adding a Background to Your Document

Document backgrounds come in handy if you plan on converting the document to a Web page. Here's how you can add a ...

Discover More

Showing RGB Colors in a Cell

Excel allows you to specify the RGB (red, green, and blue) value for any color used in a cell. Here's a quick way to see ...

Discover More

Removing Cells Containing Specific Terms

Macros are great for processing large amounts of data quickly. This tip examines several ways you can remove specific ...

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 (menu)

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

Where Is that Text?

Looking for a formula that can return the address of a cell containing a text string? Look no further; the solution is in ...

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
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 7 + 0?

2023-12-31 16:18:13

Guy

I found this by myself and thought I was the first (I was 10 when I found it out)
I put it as n/2*(n+1) and tested it with 4 4/2*(4+1) which is 2.5*5 (10)


2021-07-04 02:56:10

Roy

Of course, I write in 2021... SEQUENCE did not exist in 2016. But for folks going forward.

Well, we'll have to wait... Some ignorant (yes, "ignorant" and also "thoughtless") "Flood" message came up. Done being helpful for today I guess.


2021-07-04 02:50:12

Roy

@Brandon, and anyone interested: We can now (2021) use the SEQUENCE function to do what you want:

=SUM(SEQUENCE(1,26-8+1,8,1))

and cell addresses can be inserted for ending and starting values (26 and 8 above). One could use LET to place them at the absolute start of the formula for easy editing if one wishes them hardcoded rather than pulled from cells or formulas.

@Les McGarry: Similarly, your need could be served by using SEQUENCE inside INDIRECT to develop the addresses. That alone will produce an error though, but you can coerce the range to be used as desired by wrapping it in the SUM that you want to use anyway:

=SUM(INDIRECT("A" & SEQUENCE( ROWS(A1:A40)/4, 1, 1, 4)))

Notice using ROWS to get the number of rows in the range and then dividing by the "how many rows to move down by to get the next value" number (4 in this case). Just using ROWS by itself gets you 40 values and a wrong answer! The division by 4 (in this case) gets you exactly as many values a the sequence should get you so all is good.


2016-10-17 06:46:19

Michael (Micky) Avidan

@Les McGarry,
Try:
=SUMPRODUCT((MOD(A1:A40,4)=1)*A1:A40)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


2016-10-17 01:58:38

Les McGarry

If I have a column (or row) of numbers from A1 to A40 and want to sum the first and every 4th number (ie. A1, A5, A9, etc) is there a formula to do this?


2016-04-27 05:49:34

Michael (Micky) Avidan

@Brandon,
Try my suggested 'Array Formula' in the following picture:
(see Figure 1 below)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


Figure 1. 




2016-04-26 18:17:13

Brandon

Is there a way to do this between two digits? For instance, the sum of every integer between-and-equal-to 8 and 26 is 323. Is there a way to dynamically refer to two cells with those two or any other integers?


2016-01-06 17:51:52

Rex

Thank you!


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.