Need excel formula to sum 1+2+3...+N given a number N

G

Guest

I am looking for a formula to which I can supply a number N and have it
calculate 1+2+3+4.....+N. I realise that I can enter 1 to N in as many cells
then use SUM but this won't do for what I need to achieve.
 
B

Bernard Liengme

As Gauss found out when in elementary school" SUM(1,2, .....N) = N*(N+1)/2
So with N in A1 use = A1*(A1+1)/2

Homework?
 
B

Bob Phillips

If is always 1,2,3....N you can use Gauss's solution

=IF(ISEVEN(A1),(A1/2)*(1+A1),INT(A1/2)*(A1)+A1)

where A1 holds N

otherwise use

=SUMPRODUCT(--(ROW(INDIRECT(A1&":"&A2))))

where A1 and A2 are first and last numbers
 
G

Guest

Thanks Bob/Bernard. It's my fault - I should have explained that my numbers
may also be fractions. In fact they are each the inverse of 1 through to N.
So 1/1 +1/2 + 1/3.......1/N. I assumed the same formula could apply.

Neither of the formulas you provided seem to work in this scenario and I get
a REF error. Can you help further? Not a math or excel bunny I am afraid, so
the more explanation the better.
 
H

Harlan Grove

Bob Phillips wrote...
If is always 1,2,3....N you can use Gauss's solution

=IF(ISEVEN(A1),(A1/2)*(1+A1),INT(A1/2)*(A1)+A1)

where A1 holds N

Gauss's formula was simpler that Phillips's formula. No need to check
whether A1 is even because either A1 or A1+1 is even. So

=A1*(A1+1)/2
otherwise use

=SUMPRODUCT(--(ROW(INDIRECT(A1&":"&A2))))

where A1 and A2 are first and last numbers
....

Or

=(A2*(A2+1)-(A1-1)*A1)/2
 
B

Bob Phillips

Harlan Grove said:
Gauss's formula was simpler that Phillips's formula.

LOL. I know it is. I knew the formula, just made a hash of it as I forgot
it was as true for an odd final n umber as it was for an even.
Or

=(A2*(A2+1)-(A1-1)*A1)/2

Yeah, that's nicer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top