Closed Thread
Results 1 to 9 of 9

5-digit Random Unique Alphanumeric Code

  1. #1
    Registered User
    Join Date
    07-13-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    14

    5-digit Random Unique Alphanumeric Code

    I'm looking to create 5-digit random but unique alphanumeric codes, in the format of: letter, number, letter, number, letter. Example: d9h5e, p3g5a, c5x2w, y0v5v, s6c3q, i3v6a. I'm trying to avoid RANDBETWEEN because with the volume of codes we need to create (~6,500 to start) I want to ensure that all the codes are being created uniquely, without duplicates. And if we stick to letter, number, letter, number, letter, we will have 1.7 million variations.

    Thanks!

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: 5-digit Random Unique Alphanumeric Code

    I don't know that there is a formula solution that guarentees there are no duplicates and using RANDBETWEEN is no more suseptible than other methods.

    =CHAR(RANDBETWEEN(97,122)) & RANDBETWEEN(0,9) & CHAR(RANDBETWEEN(97,122)) & RANDBETWEEN(0,9) & CHAR(RANDBETWEEN(97,122))
    In the next column you can run a check for any duplicates with something like

    =SUMIF($A$1:A1, A1)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: 5-digit Random Unique Alphanumeric Code

    I would agree with ChemistB's solution. Be aware that RANDBETWEEN is volatile so if your sheet recalculates the values are all going to change. If you use this formula to generate a long list of numbers then check for duplicates using the formula provided, you can tweak those by hand to be unique. However, I used those formulas to generate 6500 numbers and in 20 trials did not find a single duplicate.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    07-13-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    14

    Re: 5-digit Random Unique Alphanumeric Code

    Yeah that's why I wanted to stay away from using RANDBETWEEN because we either need to generate a lot of codes the first time and never change the data or find an alternate route. I'll try to post to the macros portion as well.

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: 5-digit Random Unique Alphanumeric Code

    would be pretty simple via a macro:

    Basically,
    Have the macro author the formula ChemistB put up into two columns - then lock the values.

    Then, have the macro 'flag' any cells with a count greater than 1 (may be tricky to make fast, think I could do it though) - Rekey -those cells (add the formula again) and then lock values... check for uniqueness again (if the SUM of the counts columns = the COUNT of records, you are good to go...)

    That way it would be automatic and unique :D
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: 5-digit Random Unique Alphanumeric Code

    See attached.

    The code is pretty straightforward I would think, you would need to edit it to work on columns other than A and B. Randbetween gets you there after a couple of iterations.



    edit: I tried to mark up the parts you would need to edit for another column in red type.




    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by GeneralDisarray; 07-15-2015 at 01:38 PM.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: 5-digit Random Unique Alphanumeric Code


  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: 5-digit Random Unique Alphanumeric Code

    LOL, this was the first post....

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: 5-digit Random Unique Alphanumeric Code

    Quote Originally Posted by mcodden View Post
    I'll try to post to the macros portion as well.
    Please do not post the same question to multiple subforums. We have a rule against duplicate posts. If you feel that you should post to a different subforum please ask a moderator to move it for you.


    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Creating a 4-digit alphanumeric code string in Excel (two variations)
    By mcodden in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-05-2021, 02:52 AM
  2. Replies: 20
    Last Post: 09-27-2019, 10:11 AM
  3. [SOLVED] 3-5-3 Random, Unique Alphanumeric Code Generation
    By mcodden in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2015, 06:00 PM
  4. Replies: 2
    Last Post: 11-06-2014, 05:07 PM
  5. How to generate unique random alphanumeric 32 character codes?
    By JussiR in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-21-2014, 06:30 AM
  6. Replies: 1
    Last Post: 01-22-2013, 07:02 AM
  7. Replies: 0
    Last Post: 04-20-2012, 06:55 AM

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