i have financial equation:
FV = (PV * (1 + (x / m)) ^ (m * t) + PMT * ((1 + (x / m)) ^ (m * t) - 1) / (x / m))
i need to express x from equation. I wrote sub which solves the problem and works perfectly but what i want is to use that as function (typing in cell =F() and get instant result). So i wrote function based on my sub and it doesnt work, every time i get #Value! error in cell. Why? can anyone help me.
as you will notice i post both my sub and function(wich doesn't word) in one code, just sub syntax and variables is made as text notifications.
My code:
--------------------------------------------------------------------------
Function xcount(x, PV, FV, PMT, t, m)
xcount = FV - (PV * (1 + (x / m)) ^ (m * t) + PMT * ((1 + (x / m)) ^ (m * t) - 1) / (x / m))
End Function
--------------------------------------------------------------------------
Function F(PV, FV, PMT As Double t, m As integer) as double
'Sub pp()
'Dim x, y, PV, FV, PMT As Double
'Dim m, t As Integer
'PV = 10000
'FV = 20000
'PMT = 1820.1
't = 2
'm = 2
a = 0.0001 ' a and b are constants
b = 20
1 x = xcount(a, PV, FV, PMT, t, m)
y = xcount(b, PV, FV, PMT, t, m)
If (x * y) > 0 Then
MsgBox ("spr nera")
GoTo 2
End If
c = a - (b - a) * x / (y - x)
If Abs(xcount(c, PV, FV, PMT, t, m)) < 0.001 Then
'MsgBox (c)
F = c
'Cells(1, 1) = c
GoTo 2
End If
If xcount(a, PV, FV, PMT, t, m) * xcount(c, PV, FV, PMT, t, m) > 0 Then
a = c
Else: b = c
End If
GoTo 1
2 End Function
Bookmarks