+ Reply to Thread
Results 1 to 2 of 2

VB excel functions #Value!, making sub into a function

Hybrid View

Rupertas VB excel functions #Value!,... 10-05-2009, 05:37 PM
Rupertas Re: VB excel functions... 10-08-2009, 01:43 AM
  1. #1
    Registered User
    Join Date
    10-05-2009
    Location
    Vilnius
    MS-Off Ver
    Excel 2007
    Posts
    2

    VB excel functions #Value!, making sub into a function

    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
    Last edited by Rupertas; 10-06-2009 at 02:41 PM. Reason: forum rules

  2. #2
    Registered User
    Join Date
    10-05-2009
    Location
    Vilnius
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VB excel functions #Value!, making sub into a function

    cmon guys give any ideas why it could be wrong

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1