+ Reply to Thread
Results 1 to 6 of 6

vba to find the first unused value in a range

  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    Adelaide Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    vba to find the first unused value in a range

    I have a column with numbers such as:

    001
    002
    003
    004
    005
    007
    008
    009
    023
    075

    What I would like to do is be able to find the first number that is not used. In this case it would be 006

    I can usually google and hack my way through most things but I'm stuch on this one, help most appreciated

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: vba to find the first unused value in a range

    Hi,

    First of all they don't look like numbers. They look like text strings which contain numeric digits.
    Hence to perform arithmetic they'll need to be converted to numbers.

    One way would be the following ARRAY formula entered with Ctrl Shift Enter

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-21-2013
    Location
    Adelaide Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: vba to find the first unused value in a range

    Thanks for the reply Richard,

    I need to be able to find this value so that I can use it in an existing vba procedure. I'm don't know if the array formula helps there. (or if it does i don't know how to apply it to vba)

    The numbers are numbers. I have them custom formatted as "000"

    EDIT:

    So I can set up the array as a helper cell, for vba to reference, which will be fine.
    But the formula is returning a value of 4 when using the same range & values as I posted above

    I changed the range location if that would effect it? =SUM(--(VALUE(B2:B11)=(ROW(2:11))))+1
    Last edited by hemiceni; 10-21-2014 at 08:48 PM.

  4. #4
    Registered User
    Join Date
    01-21-2013
    Location
    Adelaide Australia
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: vba to find the first unused value in a range

    I hope I'm allowed to link to another excel forum, but I found a comprehensive thread on this just now.
    http://www.mrexcel.com/forum/excel-q...ng-number.html

    The formula I used is =IFERROR(LOOKUP(2,1/(B2:B11=(ROW(B2:B11)-ROW(B2)+1)),B2:B11)+1,1)

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: vba to find the first unused value in a range

    Hi,

    You don't need to change the ROW(1:10) element since you're wanting to compare numbers starting with 1 in B2 with a comparison number 1 which is generated by the Row(1) bit of the Row (1:10)

    Hence
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    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: vba to find the first unused value in a range

    Hello hemiceni,

    If you are still interested in how to do this using VBA, here is function that will return the missing value or Empty if there are no missing values.

    This function takes the column range to be examined and the difference between the terms. In this example range is "A1:A10" of Sheet1 and the term difference is one.

    Macro to Find Missing Value in a Sequence
    Please Login or Register  to view this content.
    Example Macro for FindMissingValue
    Please Login or Register  to view this content.
    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!)

+ 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. [SOLVED] Is there an EASY way to find unused declared variables?
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-29-2017, 06:40 AM
  2. Find last visible row with data in sheet and hide unused columns
    By specialk610 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2013, 10:04 AM
  3. To find formula to calculate unused product expiry
    By decorkewl in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-29-2013, 12:07 AM
  4. [SOLVED] Iterate Through Names, list unused: Type Mismatch with Cells.Find
    By tlafferty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 04:03 PM
  5. Count Unused Cells in a used range
    By nhrav in forum Excel General
    Replies: 6
    Last Post: 07-23-2008, 04:55 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