Sum of Numbers Smaller than input

S

Scott

If I want to be able to input a number in a cell and in another cell take the
sum of the number with all of the numbers smaller than it without a macro how
would I do it?

Example:
If I put a 6 in a cell, I want another cell to output 21 (6+5+4+3+2+1)

Thanks!
 
E

Excelenator

You need to create a custom Function


Code
-------------------
Function SUMInt(i As Long)
Dim c As Long
Dim r As Long

r = i

For c = 1 To i
r = r + (i - c)
Next c

SUMInt = r


End Functio
-------------------
 
B

bj

try
=IF(MOD(A1,2)=0,(A1+1)*(A1/2),(A1*((A1-1)/2)+A1))
if you want 6 => 21 and 6 is in A1

From what you asked (Sum of numbers less than the input number)
=if(MOD(A1,2)=1,A1*(A1-1)/2,(A1-1)*(A1-2)/2+A1-1)
if you really wanted 6=>15
 
Top