Hi all!
I have an attached file and I am trying to build a VBA function to calculate total values. First row is "RollingTime" and for example if I am trying to calculate the "Total" value. For "RollingTime" = 2 it should be
RollingTime(2)*Percentage(2)+RollingTime (1)*(1-Percentage(1))*Percentage(2)+RollingTime(0)*(1-Percentage(0)*(1-Percentage(1))*Percentage(2)
Which is 109732508*0,3 + 1017508995*(1-0,2)*0,3+1587172158*(1-0,1)*(1-0,2)*0,3
And here is the code I have tried to produce:
Function Calls(Percentage As Double, Amount As Double, RollingTime As Integer) As Double
Dim i As Integer, Previous As Double
Previous = 0
If RollingTime = 0 Then
Calls = Percentage *Amount
Exit Function
End If
For i = 1 To RollingTime
Previous = Amount.Offset(0, -i).Value + Previous * (1 - CallProb.Offset(0,-i)) ^ i
Next
Calls = CallProb * CallAmount + Previous
End Function
The problem in the function is that I (of course) cannot use "Amount.Offset" or "CallProb.Offset". So how could I determine what are the cell adresses for those arguments? So if the RollingTime argument is "2", Amount.offset(0,-2).Value would be 1587172158.
Hope I am not too confusing..
-John
Bookmarks