+ Reply to Thread
Results 1 to 7 of 7

Find 0 or smallest negative number from range

  1. #1
    Registered User
    Join Date
    03-26-2009
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    3

    Find 0 or smallest negative number from range

    HI,
    I am trying to write code that will locate either a 0 or the smallest negative number in a range, eg,

    example 1,
    8, 6, 2, 0, -0.5, -2
    the result would be 0

    example 2,
    8, 6, 2, -0.5, -2
    the result would be -0.5

    It is driving me nuts !
    Thanks in advance,
    Andy
    Last edited by agg; 03-26-2009 at 11:45 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Find 0 or smallest negative number from range

    is -0.5 smaller than -2?

    if you mean you want -2, then try the Min() function.

    e.g =Min(A1:A10)
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Find 0 or smallest negative number from range

    if it actually is that you want the closest to 0 value... (i.e. -0.5)

    you can perhaps try:

    =MAX(IF(A1:A10<=0,A1:A10),MIN(A1:A10))

    confirmed with CTRL+SHIFT+ENTER, not just ENTER

  4. #4
    Registered User
    Join Date
    03-26-2009
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Find 0 or smallest negative number from range

    Hi NBVC,


    I appreciate your quick response.

    Yes, I want the either 0 or the closest to zero on a negative number. But I cannot get your formula to work.

    Andy

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Find 0 or smallest negative number from range

    After you enter the formula in, with the proper ranges, hold the CTRL and SHIFT keys down, then press ENTER. You will see { } brackets appear around it.

    What if there are no zero or negs...? This formula will return smallest positive number.

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find 0 or smallest negative number from range

    With your sample data in Col_A, beginning in A1

    This regular formula returns zero, if it is in the list,
    otherwise it returns the negative value that is closest to zero:

    Please Login or Register  to view this content.
    Note: If no values are less than or equal to zero, it returns #N/A!

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  7. #7
    Registered User
    Join Date
    03-26-2009
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Find 0 or smallest negative number from range

    Thanks Ron & NBVC

    Works a treat !

+ 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