+ Reply to Thread
Results 1 to 3 of 3

VBA Userdefined Function returns #Value! error

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    LON
    MS-Off Ver
    Excel 2003
    Posts
    29

    Unhappy VBA Userdefined Function returns #Value! error

    Hi!
    I'm new to VBA Programming .. !
    Please have a look on the code given below. When I call this function it shows #Value! error when value in the variable Q < 8.
    I've also attached a file for your reference. Please help me out as I'm not able to resolve this issue.

    Thanks! in advance

    Regards
    Please Login or Register  to view this content.

    CDepth.xlsm
    Last edited by mandukes; 11-22-2012 at 09:41 AM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,826

    Re: VBA Userdefined Function returns #Value! error

    The Value error suggests to me some kind of math error in the function. The most likely place I can see is in the quadratic formula, and the most likely error there (since you are apparently only trying to find real roots and not complex roots) is trying to take the square root of a negative number. Since that involves more than just Q, it is hard to say for sure. Even if this isn't the immediate problem, you maybe should add some code to the function to deal with those cases where there is no positive real root.

    Here's what I'd recommend. Set a breakpoint in the function so that the function will enter break/debug mode when it is called. Then you can use the debug tools (watches, immediate window) and step through the function one line at a time to see where the error is, and work on figuring out what the error is and when it occurs.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Userdefined Function returns #Value! error

    when q<8 then (b ^ 2) - 4 * a * c is a negative number so you can't take a square root of it-not with real numbers anyway
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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