+ Reply to Thread
Results 1 to 5 of 5

Detect missing number within range

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Detect missing number within range

    Hi Guys,

    Recently I manage to find code to detect missing number within range

    Range:
    Min : 554
    Max: 557

    Code:
    =SMALL(IF(COUNTIF(K2:K100,ROW($K$554:$K$557))=0,ROW($K$554:$K$557),""),ROW())

    But the range is hard-coded, how to change from hard-coded to Cell name instead?

    I try below but no luck, lets say min range is at cell A2 and max range at cell B2

    =SMALL(IF(COUNTIF(K2:K100,ROW($K$(A2):$K$(B2)))=0,ROW($K$(A2):$K$(B2)),""),ROW())

    Any clue?

    Thanks
    Azhan
    Malaysia

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Detect missing number within range

    Hello Azhan,

    The easiest way is to create a named range. You can then use that name in the formula. It will make you formula easier to understand and change when needed.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Detect missing number within range

    Quote Originally Posted by Leith Ross View Post
    Hello Azhan,

    The easiest way is to create a named range. You can then use that name in the formula. It will make you formula easier to understand and change when needed.
    Thanks for your reply Leith!

    I'm not very sure on how to use the "named range". The range is not fixed and the value is change time to time from other Cell's macro.

    Let say my min range is in cell A2, A2 value depend on other Cell's macro and that is why I need to define Cell name in above macro instead of hard-coded the value.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Detect missing number within range

    ah there is a slight flaw in the formula as written ,the end bit row() is to determine the first smallest but this depends on the formula being in row 1
    to make it more dynamic you can put in a2 =min(k2:k100) and in b2 max(k2:k100)
    or whatever your limits are instead
    then use
    =SMALL(IF(COUNTIF($K$2:$K$100,ROW(INDIRECT($A$2&":"&$B$2)))=0,ROW(INDIRECT($A$2&":"&$B$2)),""),ROWS($A$1:A1)) array entered and drag down

    but now as i see you mention macro?
    indirect is not one you can use in vba
    INDIRECT() No direct equivalent - use Range,
    Cells, Offset, or any other way of
    referencing cells
    Attached Files Attached Files
    Last edited by martindwilson; 06-25-2012 at 09:57 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    06-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Detect missing number within range

    Quote Originally Posted by martindwilson View Post
    ah there is a slight flaw in the formula as written ,the end bit row() is to determine the first smallest but this depends on the formula being in row 1
    to make it more dynamic you can put in a2 =min(k2:k100) and in b2 max(k2:k100)
    or whatever your limits are instead
    then use
    =SMALL(IF(COUNTIF($K$2:$K$100,ROW(INDIRECT($A$2&":"&$B$2)))=0,ROW(INDIRECT($A$2&":"&$B$2)),""),ROWS($A$1:A1)) array entered and drag down

    but now as i see you mention macro?
    indirect is not one you can use in vba
    INDIRECT() No direct equivalent - use Range,
    Cells, Offset, or any other way of
    referencing cells

    Nice one wilson...it works like charm!! hehe..

    1 last question though, how do i ignore #NUM! value in order to search MAX/MIN range using =MAX(K:K) function ?

+ 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