+ Reply to Thread
Results 1 to 12 of 12

Find next available smallest number in a range

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Cambridge, UK
    MS-Off Ver
    Excel 2013
    Posts
    48

    Find next available smallest number in a range

    Hi there,

    I'm a bit stumped with this apparently simple question. My array formula skills seem to have abandoned me this morning.

    Suppose you have a list of numbers in a range like this:

    Please Login or Register  to view this content.
    I want to find the smallest number that has not been used. In this case it would be 5.

    Thank you
    <--- Please click the star to say thank you

  2. #2
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,941

    Re: Find next available smallest number in a range

    Pls attach sample file
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  3. #3
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Find next available smallest number in a range

    I assume you want a positive integer. 0 is less than 5 and it hasn't been used.
    Happy with my advice? Click on the * reputation button below

  4. #4
    Forum Contributor
    Join Date
    02-07-2013
    Location
    Karachi, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    290

    Re: Find next available smallest number in a range

    Hi Peter,

    Use this {array formula} :
    =MIN(IF(ISNA(MATCH(ROW($1:$400),A$2:A$401,0)),IF(COUNTIF(C$1:C1,ROW($1:$400))=0,ROW($1:$400))))

    As seen here:
    http://answers.microsoft.com/en-us/o...6988cde?auth=1

    Regards,

  5. #5
    Registered User
    Join Date
    06-14-2012
    Location
    Cambridge, UK
    MS-Off Ver
    Excel 2013
    Posts
    48

    Re: Find next available smallest number in a range

    Quote Originally Posted by Khalidngo View Post
    Hi Peter,

    Use this {array formula} :
    =MIN(IF(ISNA(MATCH(ROW($1:$400),A$2:A$401,0)),IF(COUNTIF(C$1:C1,ROW($1:$400))=0,ROW($1:$400))))

    As seen here:
    http://answers.microsoft.com/en-us/o...6988cde?auth=1

    Regards,
    What a beautiful formula - thank you so much.

    (Crooza - yes, in my example I meant a positive integer but I've since adapted Khalidngo's formula to work with any given lower bound)

  6. #6
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Find next available smallest number in a range

    or try this one. assuming you want the smallest (starting from the smallest already there) as an array formula

    =MIN(IF(ISERROR(MATCH(ROW(A1:A6)-1+MIN(A1:A6),A1:A6,0)),ROW(A1:A6)-1+MIN(A1:A6),99999999))

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find next available smallest number in a range

    Here's another one...

    Assuming the range of numbers is from 1 to 100.

    Data Range
    A
    B
    C
    1
    1
    5
    2
    7
    3
    2
    4
    2
    5
    4
    6
    3
    7
    ------
    ------
    ------


    This array formula** entered in C1:

    =MIN(IF(ISNA(MATCH(ROW(INDIRECT("1:100")),A1:A6,0)),ROW(INDIRECT("1:100"))))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  8. #8
    Forum Contributor
    Join Date
    02-07-2013
    Location
    Karachi, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    290

    Re: Find next available smallest number in a range

    Quote Originally Posted by Tony Valko View Post
    =MIN(IF(ISNA(MATCH(ROW(INDIRECT("1:100")),A1:A6,0)),ROW(INDIRECT("1:100"))))
    Hi Biff,
    Nice formula,

    Just a question, INDIRECT necessary here?

    Regards,
    Last edited by Khalidngo; 02-16-2016 at 06:23 AM. Reason: Quote selected text

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find next available smallest number in a range

    =MIN(IF(ISNA(MATCH(ROW(INDIRECT("1:100")),A1:A6,0)),ROW(INDIRECT("1:100"))))

    Quote Originally Posted by Khalidngo View Post
    Just a question, INDIRECT necessary here?
    INDIRECT makes the formula more robust.

    If we use:

    ROW(1:100)

    And happen to insert new rows before row 1 then the formula will return incorrect results.

    ROW(1:100)

    Becomes ROW(2:101)

    So that means we start searching for the missing numbers 2 through 101 instead of 1 through 100.

    INDIRECT can account for that.

    ROW(INDIRECT("1:100"))

    Will always refer to row 1 through 100.

  10. #10
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,658

    Re: Find next available smallest number in a range

    Another non-array formula:

    =MATCH(0,INDEX(COUNTIF($A$1:$A$6,ROW(INDIRECT("1:100"))),),0)
    Quang PT

  11. #11
    Forum Contributor
    Join Date
    02-07-2013
    Location
    Karachi, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    290

    Re: Find next available smallest number in a range

    Quote Originally Posted by Tony Valko View Post

    INDIRECT makes the formula more robust.

    If we use:

    ROW(1:100)

    And happen to insert new rows before row 1 then the formula will return incorrect results.

    ROW(1:100)

    Becomes ROW(2:101)

    ROW(INDIRECT("1:100"))

    Will always refer to row 1 through 100.
    Hi Biff,
    Got it, thanks for the detailed example.

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Find next available smallest number in a range

    You're welcome!

+ 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. find the smallest number
    By sanju2323 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-24-2015, 10:12 AM
  2. [SOLVED] Find the smallest number in a column that has some #N/A in it.
    By JimLau in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-22-2014, 11:02 AM
  3. [SOLVED] find smallest Number in a col
    By bnwash in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-12-2013, 10:26 PM
  4. Find the smallest number in a range of cells that are separated by boarder
    By svetlich in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2012, 03:58 AM
  5. Replies: 1
    Last Post: 04-20-2010, 02:34 PM
  6. Find 0 or smallest negative number from range
    By agg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-26-2009, 11:42 AM
  7. find the smallest number greater than Zero
    By carsto in forum Excel General
    Replies: 3
    Last Post: 10-06-2006, 04:25 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