If Then ElseIf problem

WineSnob

Not Bright but TENACIOUS
Local time
Today, 18:54
Joined
Aug 9, 2010
Messages
211
I am trying to get a calculation to change when a cerrtain year starts. It is not doing what I want and I have tried multiple times.
I want the calculation to be -
Value = Initial * (1+ nRate) until I reach cYear then take the last Value and add cAmount and continue until end.
Here is the code that works as long as the cYear is not 1. Not sure how to add elseif to it to change when the calculation changes.

Given the testfunction arguments below the answer should be 283997.93
Year 1 should = 106000
Year 2 should = 112360
Year 3 should = 129701.60
etc until year 10 should = 283997.93

Thanks in advance!
Function fnGetDeffered(nYear As Integer, Initial As Currency, nRate As Double, cYear As Integer, cAmount As Currency) As Currency
Dim I As Integer
Dim Value As Currency
Dim nValue As Currency
For I = 1 To nYear
If I = 1 Then
Value = Initial * (1 + nRate)
Else

Value = (Value + cAmount) * (1 + nRate)
End If
Debug.Print Value
fnGetDeffered = Value

Next I


End Function

Function testdeffered()
Debug.Print fnGetDeffered(10, 100000, 0.06, 3, 10000)
 

Users who are viewing this thread

Back
Top Bottom