+ Reply to Thread
Results 1 to 4 of 4

Create random 6 digit number with no duplicates.

  1. #1
    Registered User
    Join Date
    08-29-2021
    Location
    USA
    MS-Off Ver
    Office 10
    Posts
    1

    Lightbulb Create random 6 digit number with no duplicates.

    Hello,
    Here is my scenario. I have an excel spreadsheet with Patient ID's. I am trying to create a 6 digit random number for each patient. Note that the script should automatically generate the random number in the adjacent cell each time a new patient is added to the spreadsheet. Once the random 6 digit number is generated, there are two scenarios to keep in mind.
    1. The randomly generated numbers should not change. Once generated, each random number should remain static as it will be linked with the patient across time.
    2. The random numbers should not repeat. Each randomly generated number must be unique to each patient.

    There is only one master file and when the user enters a new patient into the spreadsheet, a random 6 digit number should automatically populate. (the random number should not repeat any previously generated numbers) The 6 digit number range can be set to 5000001 - 500999.

    Thank you so much!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Create random 6 digit number with no duplicates.

    Here is a VBA solution. Attach this to a Command Button

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    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: Create random 6 digit number with no duplicates.

    Your OP suggests that there are just 999 random numbers with the digits '500' being common to each.

    Another option would be to hold a list of unique random numbers and each time a new patient is created pick the number at the top of the list, copy and paste it to the patient record and then delete the top number in the list.
    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.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Create random 6 digit number with no duplicates.

    why not MAX(Current_number_to date) +1: start at 5000001 and just add sequentially for next patient.

+ 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] How to get first or second digit number from the random formula
    By Jeewon in forum Excel General
    Replies: 4
    Last Post: 02-08-2021, 05:13 PM
  2. Replies: 2
    Last Post: 10-09-2020, 03:53 PM
  3. Random generating a 10 digit number that only contains specific digits.
    By mutzie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-03-2017, 09:46 AM
  4. Replies: 20
    Last Post: 05-10-2016, 06:05 PM
  5. Replies: 6
    Last Post: 08-31-2015, 03:08 PM
  6. Replies: 10
    Last Post: 11-24-2011, 10:34 AM
  7. Random 8 digit number?
    By KennyS in forum Excel General
    Replies: 6
    Last Post: 08-21-2006, 01:30 PM

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