PDA

View Full Version : writting sum function in VBA



me84
05-28-2008, 10:07 AM
hi I am trying to practice my VBA and am trying to write a "series" summation function. i.e in mathematical terms the function is...
∑(1+i)^n


so far I have the following but I do know that there is a problem with my loop which is only calculating (1+i)^n rather than summing.

Function Summation (interest as single, n as single)
Do
j = 1
Summation = (1+i)^n
j = j+1
loop until j = n
End Function

Would like to hear everyones comments/ advice

Norie
05-28-2008, 10:39 AM
Perhaps you should actually try summing/adding something?

Summation = Summation + (1+i)^n

mikerickson
05-28-2008, 10:23 PM
That loop will not terminate unless n=2. i is being reset to 1 at the start of each iteration.

Changing line order will prevent that j=1
Do