+ Reply to Thread
Results 1 to 9 of 9

Finding next available number

Hybrid View

  1. #1
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Finding next available number

    Hi all =D

    I am trying to make a macro to tell me the next lowest unit number available in a parts list.
    I have unit numbers listed down Multiple times.
    The unit numbers start at 100 and go up in increments of one, but not necessary in order and some may be missed/removed so these numbers need to be reused.

    There are gaps of 1 row to split up different parts.
    Its probably not all that clear explaining it so i will attach a Dummy workbook too.

    Attachment 247577
    I dont like to use code i dont understand
    it makes it hard to use in other situations
    so please try to be as clear and patent as possible with me

    Criticism is welcomed

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Finding next available number

    Hi, FRIEL,

    canīt download the attachment. Maybe you can use WorksheetFunction.Max(Range("$A$2:$A400")) + 1 for solving the problem where I assumed the list to be in Column A. Suit the upper row number to match one row less than the new one should be added.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Finding next available number

    cant use Max as it isn't always going to be the largest number next.
    if i remove unit 105, for instance, then unit 105 will be the next available number.

  4. #4
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Finding next available number

    that attachment hasnt worked.

    example.xlsx

    this should work

  5. #5
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Finding next available number

    cant use Max as it isn't always going to be the largest number next.
    if i remove unit 105, for instance, then unit 105 will be the next available number.

    i think the attachment works now.
    unfortunately my fire walls wont let me download anything from here so i cant check

  6. #6
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Finding next available number

    cant use Max as it isn't always going to be the largest number next.
    if i remove unit 105, for instance, then unit 105 will be the next available number.

    i think the attachment works now.
    unfortunately my fire walls wont let me download anything from here so i cant check

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Finding next available number

    Hi, FRIEL,

    I realized that as well when looking at the workbook and reading the question again.

    Sub TellAvailNr()
    Dim lngFree As Long
    
    lngFree = 100
    Do While WorksheetFunction.CountIf(Range("D9:D" & Range("D" & Rows.Count).End(xlUp).Row), lngFree) > 0
      lngFree = lngFree + 1
    Loop
    
    MsgBox lngFree
    End Sub
    100 is not present, 124 would be the next number if you change 100 to 101.

    Ciao,
    Holger

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding next available number

    The link to your attachment is invalid (Post #1).

    Please try again.

    [EDIT]
    Okay, it's fine in Post#3
    Last edited by Marcol; 07-03-2013 at 04:51 AM.

  9. #9
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Finding next available number

    oh yeah, that's my bad it starts at 101

    working exactly as i wanted.

    thanks HaHoBe

+ 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