+ Reply to Thread
Results 1 to 15 of 15

Random List Generator How to copy Columns A and B to Sheet 2

  1. #1
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Random List Generator How to copy Columns A and B to Sheet 2

    I'm trying to create a random list generator for drug testing via a userform. Employee number is in column A and the employee Name is in Column B. Can anyone tell me how I get get the employee number in column A to copy over to sheet 2 with the employee name. I've attached a sample workbook. Any help would be greatly appreciated.Random.xlsm

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

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    Here is one solution possibility:

    On sheet2, in column B, type =randbetween(3, 11236)
    On sheet2, in column C, type =VLOOKUP(B1,Sheet1!$A$2:$B$860,2,FALSE)

    copy them down as many rows as you need to get tests for. A note of importance, your list of employees has fewer numbers than the difference between 3 and 11236. These were the Min and Max of your list. These numbers (missing) will generate #NA. You may have to expand your output to get the number of random selections you are looking for.
    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 Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    Thank you, but I'm really only trying to figure out how to get the employee number to copy over along with the employee name.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    This might suit you.
    The random selection routines that I added return N randomly selected employees. Those employees are not checked against the "already tested" list in Sheet2.
    I've added the feature that the date (of test?) is added to Sheet2 for record keeping.

    If you want to test the selected against the list of in sheet2, I would use a different approach.
    Randomize the whole employee list, write that in Sheet2 without dates.
    When you want to test 3 (or 5) employees, test the first 3 (or 5) from the list in Sheet2 that don't have a date next to their names. Add the date of testing to those employees.

    Note the DefaultWriteRange function in the UF code module and the EmployeeList function in Module 3.
    If you change your workbook layout, these should be adjusted, but those are the only places that these hard coded values need to be changed.
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    Oh my goodness, this is perfect mikerickson, I can use this for sure. Thank you so much for this.

  6. #6
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    Would it be possible to select a percentage of the employees listed ?

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    All you have to do is control the Size argument that is passed to ChooseNWorkers
    If you want to choose 32% of your workers

    Please Login or Register  to view this content.
    I just noticed that you probably want to change the default DestinationRange inside ChooseNWorkers.

  8. #8
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    I'm not sure I'm following you, I'm attaching what I have right now.
    Attached Files Attached Files

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    The first argument of ChooseNWorkers is the number of workers to be chosen from the EmployeeList.

    To select N percent, just set that first argument to N%*number of workers (which is EmployeeList.Rows.Count)

  10. #10
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    I'm trying to understand, but I'm just not getting it at all.

  11. #11
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    I liked the random selection that you wrote, but how can I incorporate the percentage.
    Please Login or Register  to view this content.

  12. #12
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    Change this line
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    I changed it but I'm getting a Run time error 424 object required

  14. #14
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    Did I spell that right, or is the function's name EmployeesList?

  15. #15
    Forum Contributor guitarsweety's Avatar
    Join Date
    10-30-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    188

    Re: Random List Generator How to copy Columns A and B to Sheet 2

    You nailed it the function was named "EmployeesList". Thanks for this! I've been working on this all day and you've played a major part in my success.

+ 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. Workbook&sheet macro generator from a list
    By andrugrasu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2013, 08:55 AM
  2. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  3. Replies: 4
    Last Post: 12-22-2012, 01:41 PM
  4. random name generator
    By rookie37 in forum Excel General
    Replies: 16
    Last Post: 06-23-2009, 03:00 AM
  5. Random Generator
    By Duncan1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2007, 08:07 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