Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
LAdekoya
 
Posts: n/a
Default Need excel formula to sum 1+2+3...+N given a number N

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.
  #2   Report Post  
Bernard Liengme
 
Posts: n/a
Default

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?
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"LAdekoya" wrote in message
...
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.



  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default

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


--
HTH

Bob Phillips

"LAdekoya" wrote in message
...
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.



  #4   Report Post  
LAdekoya
 
Posts: n/a
Default

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.


"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

otherwise use

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

where A1 and A2 are first and last numbers


--
HTH

Bob Phillips

"LAdekoya" wrote in message
...
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.




  #5   Report Post  
Bob Phillips
 
Posts: n/a
Default

=SUMPRODUCT(--(1/ROW(INDIRECT(B1&":"&B2))))

--
HTH

Bob Phillips

"LAdekoya" wrote in message
...
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.


"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

otherwise use

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

where A1 and A2 are first and last numbers


--
HTH

Bob Phillips

"LAdekoya" wrote in message
...
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.








  #6   Report Post  
LAdekoya
 
Posts: n/a
Default

Thanks

Louis

"Bob Phillips" wrote:

=SUMPRODUCT(--(1/ROW(INDIRECT(B1&":"&B2))))

--
HTH

Bob Phillips

"LAdekoya" wrote in message
...
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.


"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

otherwise use

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

where A1 and A2 are first and last numbers


--
HTH

Bob Phillips

"LAdekoya" wrote in message
...
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.






  #7   Report Post  
Harlan Grove
 
Posts: n/a
Default

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

  #8   Report Post  
Bob Phillips
 
Posts: n/a
Default



"Harlan Grove" wrote in message
ups.com...
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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula in an Excel comment The Window Cleaner Excel Discussion (Misc queries) 0 March 10th 05 11:03 AM
Excel should have a simpler subtraction formula similar to "sum". Darius Excel Worksheet Functions 5 February 21st 05 11:14 PM
How do I get the formula bar in excel 2003 unionhall Excel Discussion (Misc queries) 1 February 17th 05 10:10 AM
Need excel formula to display 28.50hrs in HRS & MINS? rbc Excel Worksheet Functions 4 January 6th 05 12:21 PM
Suddenly Excel can't calculate formula!!! Bob H Excel Worksheet Functions 2 November 30th 04 08:35 PM


All times are GMT +1. The time now is 05:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"