+ Reply to Thread
Results 1 to 5 of 5

VB sqrt problem

  1. #1
    Registered User
    Join Date
    10-02-2016
    Location
    Latvia
    MS-Off Ver
    MS 16
    Posts
    3

    VB sqrt problem

    Hello!
    Have a assignment for high school in Excel Visual basics.
    So I wrote function func = sqrt(x + 3) and when i type in cell that x = (-4) or less it shows #VALUE! and no matter what I write in arguments it never changes.
    I even wrote in arguments that :
    If x < (-3) Or x = (-3) Then
    func = "error"

    But it does not work for me.
    I am new to Visual basics.
    I guess it is somehow connected to #NUM! error or do I need more arguments, even though I can't really solve it.
    Please help!

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VB sqrt problem

    assignment for high school
    Did you miss the class on Square Roots?

    THe square root of a negative number is an imaginary number, not a real number, so Excel cannot calculate it.

    You should read this

  3. #3
    Registered User
    Join Date
    10-02-2016
    Location
    Latvia
    MS-Off Ver
    MS 16
    Posts
    3

    Re: VB sqrt problem

    Yea, I know that and that is not the problem, the problem is that I have to prevent it and when someone wants to do that, I have to give back aswer with
    String = "error".
    But instead I get #VALUE! error.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VB sqrt problem

    I have to prevent it ...
    Helps if you actually mention that in the first place. Excel has some Functions to handle errors.

    You can also use the IF() Function to test the input value and return a message if invalid or the actual result if valid.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,415

    Re: VB sqrt problem

    It is difficult to understand your question without seeing the code that you have.

    If it will help, in this tutorial http://www.excelforum.com/tips-and-t...uild-udfs.html :
    Please Login or Register  to view this content.
    This is one of the intermediate stages and shows how I might handle the "error" when the discriminant for the quadratic equation is negative (seems like a very similar problem to what you describe here).
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Problem with sqrt
    By Bartek120 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2016, 06:11 PM
  2. =+g12*2.20452+10.518+(2*sqrt(10.9)-2*sqrt(g13))
    By luisfsantos in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-13-2013, 08:21 AM
  3. Excel 2007 : SQRT problems
    By frdranger25401 in forum Excel General
    Replies: 1
    Last Post: 04-14-2011, 01:56 PM
  4. UDF using SQRT function
    By Vlad999 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2007, 09:14 PM
  5. [SOLVED] find exact values of SQRT
    By big_ears in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2006, 03:00 AM
  6. [SOLVED] We have SQRT. But what is the function for other roots - cubed ro.
    By ACC in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-02-2005, 04:06 PM
  7. how to multiply 29,5 with sqrt of 12
    By Smiley in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-10-2005, 02:06 PM

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