+ Reply to Thread
Results 1 to 23 of 23

Need to create unique pin codes

  1. #1
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Need to create unique pin codes

    Hi I really need help. I need to create as many unique 4 digit codes using numbers 1 to 20 for staff to use. I have been trying various formulas but keep getting duplicates. What should I do?

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Need to create unique pin codes

    Erm... Can you explain a 4 digit code using numbers 1 to 20??
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  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,696

    Re: Need to create unique pin codes

    Your description is a little confusing because how do you compose 4-digit codes from the numbers 1-20? Do you mean that you have to generate 20 different unique 4-digit codes?

    Here is one example. I don't know of a way to do this by formulas alone. This method requires one manual step to refresh the list.

    There are three columns. The first column is a sequence number, which you can use to assign PINs to people. This column can be anything you want--names, employee numbers, account numbers. The second column is the PIN associated with that sequence number. There are 1000 unique PINs in this column (there are 1000 unique possible 4-digit PINs). The third column is random numbers. To generate a fresh set of PINs, click on the dropdown at the top of column C and select "Sort smallest to largest." The PINs will be shuffled and reassigned to the sequence numbers.

    It is also possible to do this with macros, but this was a little quicker to put together.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Sorry all. It's late and the pressure is getting to me.

    Example, using 1 to 20 random but unique limited to 4 numbers

    5 9 10 11 12
    20 7 14 1 19

    Etc. etc.

  5. #5
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    I bought this call logging system to assign to people when they make an outgoing call and it was cheap so now I have to create and manually enter codes to accept when they use the phone

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

    Re: Need to create unique pin codes

    Must be really late. Your examples have five numbers. Please try again...

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Need to create unique pin codes

    Here's a little bit of code, which randomly generates a set of five numbers between 1-20, with no duplicate combinations.

    Double click the PIN heading to add a new combination to the list.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Apologies it's 5 digit. Thank you 6Stringjazzer for pointing out

  9. #9
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Ollyxls. Thank you for that. I will give it a try at the office today.

  10. #10
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Quote Originally Posted by OllyXLS View Post
    Here's a little bit of code, which randomly generates a set of five numbers between 1-20, with no duplicate combinations.

    Double click the PIN heading to add a new combination to the list.

    Hi OllyXLS,
    I have tried this and i noticed i have duplicates in some pins. eg,:
    9,18,6,10,10
    19,15,11,2,11

    Also if i want to amend this how can I should I want to change number range?

  11. #11
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Need to create unique pin codes

    Ah, so you don't want duplicates in each set of 5 numbers? That wasn't clear...

    Let me have a look at it.

  12. #12
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Need to create unique pin codes

    Okay - change the code to:
    Please Login or Register  to view this content.
    To change the number range, amend the numbers coloured red.
    To change the count of number returned in the overall PIN combination, change the number coloured blue. This loops from 0, not 1, so enter one less than the value you need - so, for 5 x numbers, enter 4 here.

  13. #13
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Quote Originally Posted by OllyXLS View Post
    Ah, so you don't want duplicates in each set of 5 numbers? That wasn't clear...

    Let me have a look at it.
    thank you - feel like a fool asking for help. Appreciate the patience with me.

  14. #14
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Awesome - works great.

    I now did not see any duplicate numbers in each - PERFECT

    It works great. Now I noticed that there are many different number sets and I can get just by double clicking the "PIN" - is there a way to run every possible number set for that range? I should then be able to load that CSV file into my systems data base. If it is possible, just to know how many sets i can get till it runs out.

  15. #15
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Hi Olly,
    Any help with last request?

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need to create unique pin codes

    There's almost 2M permutations -- is there really value in listing them all?
    Entia non sunt multiplicanda sine necessitate

  17. #17
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Need to create unique pin codes

    Quote Originally Posted by shg View Post
    There's almost 2M permutations -- is there really value in listing them all?
    Yeah, that - there are 20 x 19 x 18 x 17 x 16 = 1,860,480 permutations. What do you want to do with the complete list?!

  18. #18
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Quote Originally Posted by OllyXLS View Post
    Yeah, that - there are 20 x 19 x 18 x 17 x 16 = 1,860,480 permutations. What do you want to do with the complete list?!
    Hi. Thank you for replies. If I potentially have that many permutation from this code then it's fine the way it is. It will be enough for me to use. Thanks again for the reply.

  19. #19
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Hi Shg, thank you for replying. With that many permutations I surely will be ok for a long time so at this stage no further action required. Appreciate the reply.

  20. #20
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need to create unique pin codes

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  21. #21
    Registered User
    Join Date
    02-10-2014
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need to create unique pin codes

    Thank you for that information.

    Appreciate the response and actions going forward

  22. #22
    Registered User
    Join Date
    09-20-2021
    Location
    Pittsburgh PA
    MS-Off Ver
    Microsoft 365 Apps for Enterprise
    Posts
    1

    Re: Need to create unique pin codes

    How could we update this macro if we needed this to generate PINs without sequential numbers?

  23. #23
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Need to create unique pin codes

    Quote Originally Posted by a_dumb_fake_name View Post
    How could we update this macro if we needed this to generate PINs without sequential numbers?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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. Creating Unique codes from two columns
    By tanknijenhuis in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-12-2013, 02:12 PM
  2. [SOLVED] create list of unique staff numbers with unique work codes
    By shaz0503 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-01-2013, 08:57 PM
  3. Unique codes
    By Faith79 in forum Excel General
    Replies: 12
    Last Post: 10-23-2009, 01:48 PM
  4. Trying to create codes
    By baf3472 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-29-2007, 12:29 PM
  5. [SOLVED] Counting Unique Codes
    By pgiessler in forum Excel General
    Replies: 1
    Last Post: 08-16-2006, 12:00 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