+ Reply to Thread
Results 1 to 15 of 15

ID number generation - with prefix

  1. #1
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Thumbs up ID number generation - with prefix

    Hi everyone,

    I am currently working on a personal project, creating a macro in excel to better manage a register of businesses.
    It is incomplete at the moment.

    Currently, I have a userform with a field licencetext where the user can enter a number which acts as an ID number (the prefix "FB" is added during transfer of data from the userform to the sheet.

    However, if the field is left blank, a would like excel to generate the next unique three digit number available (and verify that is not a duplicate)

    Any ideas on how to do this? I have had a look at some other threads on the net, but can't seem to find something relevant or easy to understand - I am new to VBA and entirely self-taught mainly through just google and looking at examples... yea I know, it's pretty bad form XD


    Edit. Attachment included - please note the code and layout of userform are not complete
    Attached Files Attached Files
    Last edited by ania1224; 04-09-2018 at 07:27 PM. Reason: solved

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: ID number generation - with prefix

    generate the next unique three digit number available
    assume you have a list of sorts....so take the last number and plus 1?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: ID number generation - with prefix

    Post an example file with desensitized data if possible.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: ID number generation - with prefix

    Attachment added to original post

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: ID number generation - with prefix

    Try this.
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: ID number generation - with prefix

    so you have FB123, FB456, FB431

    what would you expect to see as the next number?
    FB124? then 125 126 etc
    FB432 then 433 434 etc
    FB456 then 457 458
    or something else entirely?

  7. #7
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: ID number generation - with prefix

    Quote Originally Posted by humdingaling View Post
    so you have FB123, FB456, FB431

    what would you expect to see as the next number?
    FB124? then 125 126 etc
    FB432 then 433 434 etc
    FB456 then 457 458
    or something else entirely?
    The number following the highest number in the set.

  8. #8
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: ID number generation - with prefix

    Quote Originally Posted by bakerman2 View Post
    Try this.
    Please Login or Register  to view this content.

    Didn't seem to work for me

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,786

    Re: ID number generation - with prefix

    That's not much use, really. In what way did it not seem to work? Outcome? Error messages? What???
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  10. #10
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: ID number generation - with prefix

    There was no error when running macro, but regardless no new number generated and input into the worksheet.
    Last edited by AliGW; 04-09-2018 at 03:04 AM. Reason: Please don't quote unnecessarily!!!

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: ID number generation - with prefix

    Oh yes, it works.
    Run this in your example file.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: ID number generation - with prefix

    Can attach a worksheet where this works? I cannot seem to work out where it is going wrong on mine, the Msgbox does not appear. Perhaps I am putting it in the wrong place?
    Last edited by AliGW; 04-09-2018 at 03:03 AM. Reason: Please don't quote unnecessarily!!!

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: ID number generation - with prefix

    Your wish is my command.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: ID number generation - with prefix

    Quote Originally Posted by bakerman2 View Post
    Your wish is my command.
    Thanks, you're the best. I see now where I was going wrong. Thanks

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: ID number generation - with prefix

    Glad to help and thanks for rep+.

+ 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. Add prefix to number
    By sherlock57 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2017, 11:27 AM
  2. Prefix number in formula
    By wholly1971 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-19-2016, 12:12 PM
  3. Replies: 2
    Last Post: 08-11-2015, 05:22 AM
  4. [SOLVED] Number prefix for employee id
    By iqubalemco in forum Excel General
    Replies: 5
    Last Post: 10-29-2014, 12:35 AM
  5. Adding 0 as prefix for number when number is quoted
    By VIJEXCEL in forum Excel General
    Replies: 3
    Last Post: 04-05-2011, 05:38 PM
  6. Prefix number with '
    By JohnD0e in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2010, 03:48 AM
  7. [SOLVED] Add prefix to number
    By sprinter1801 in forum Excel General
    Replies: 5
    Last Post: 02-06-2010, 09:22 AM

Tags for this Thread

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