+ Reply to Thread
Results 1 to 23 of 23

Distribute names randomly

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Distribute names randomly

    Hello forum experts
    My request is direct and simple ...
    I have names in column A and there are three places where I need to distribute those people to according to column C

    Simply I need to distribute those names in random way ( no duplicate random is allowed .. I mean if the person is chosen before not to include him again) ..
    The distribution would depend on column C
    As in the sample : place1 would include 9 persons and place2 would include 4 and place3 would include 7 persons
    Thanks advanced for help

    Note :I need to deal with the issue using arrays or dictionary method if possible
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Distribute names randomly

    Do you want the solution in VBA or standard formulas with some help columns? Should the results be sorted? Should it be automated by a Change event trigger or manually ran if VBA was used?

    I would normally use Change event and sort using VBA.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    Thanks a lot for reply
    I need the solution using vba arrays not formula arrays .. no need for sorting results ..
    I would manually ran it using form button
    Thanks advanced for help

  4. #4
    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: Distribute names randomly

    Hi,

    Here's one solution. First remove the merged cells at J6

    Please Login or Register  to view this content.
    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.

  5. #5
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    Maybe :

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    @Mr. Richard
    That's great solution. Thanks a lot for wonderful help
    Just note that places are not fixed .. there will be over 100 places

    @Mr. karedog the king of vba arrays
    Thank you very much for great and awesome code
    Just a little addition : to put the places (which would be variable) in first row F1:H1
    Please just point me to changes that I should do ..
    Last edited by YasserKhalil; 05-02-2016 at 11:22 AM.

  7. #7
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    You are welcome. It should be :

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Distribute names randomly

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    Thank you very much Mr. Karedog
    Now it is perfect .. you are very very helpful

    Mr. Kenneth thanks a lot for the code
    I tested it and it works well but the results are not correct exactly as the names should be distributed randomly (all the names .. and each name is just distributed once)

  10. #10
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    Glad I can help.


    Regards

  11. #11
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Distribute names randomly

    I don't know what you mean. It is obvious that mine gives random integers with no duplicates. If not obvious:
    Please Login or Register  to view this content.
    As you can see, the random numbers could be sort but you said that you did not want that. I normally sort both the non-dup list and the random integer list.

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    Thanks a lot Mr. Kenneth for reply
    This is a snap shot of results after testing your code in post #8
    The colored cells are duplicate names and that is not allowed ..
    Untitled.png


    @Mr. Karedog
    It seems that I need some modifications to your great and awesome code
    I need to deal with each part in a separated array ..because they may be non-adjacent as attached
    I mean to store Names in an array, Places in an array, Number of places in an array then to deal with them ..
    I am so sorry for modifying my request

  13. #13
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    Please upload a sample workbook which can describe the new layout.
    Different layout will produce different macro too.

  14. #14
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    Based on original file, but the input array is splitted to 3 arrays :

    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    Thanks Mr. Karedog for this wonderful code
    That's exactly what I need .. Thank you very very much
    Best Regards
    Last edited by YasserKhalil; 05-03-2016 at 01:14 AM.

  16. #16
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    You are welcome, glad to help.


    Regards

  17. #17
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Distribute names randomly

    karedog's Test2 had a run-time error for me.

    Yasser, your posts are interesting sometimes. I wonder if you really need all that much help or you are just trying to get help for others.

    In any case, as a Civil Engineer, we solve problems in 3 steps: (1) given, (2) required, and (3) solution. (1) and (2) are why I usually ask for simple example files with before and after views. You gave us (1) just fine in the file but only gave (2) partially in post #1. I can't really see all the impacts of the requirements (2) that you detailed at the end of post #12 without more specifics.

    When I post solutions, I most always test them. What I like to do is to teach concepts, rather than tailored solutions. I don't always include error catching routines but do try to program in modules (reusable code) to illustrate concepts. Since I don't know all what you mean in post #12, Main1 just solves the first part of #12.

    Please Login or Register  to view this content.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    Thanks a lot Mr. Kenneth for this wonderful help
    I tested the last post and it is very excellent ...
    Thank you very much for time spent in this issue

    In fact I am fond of excel vba and I am learning each day new things .. but may be because of English in not my native language .. this may be an obstacle a little
    And this is happened with you as you didn't get my request clearly from the beginning..
    Generally I am trying to do my best .. and as for the issues : some of them related to my work and others for my friends that working in various fileds

    @Mr. Karedog
    As for the last line of the fantastic code
    Please Login or Register  to view this content.
    I know this may get you angry as this is a new request
    As for the results .. In need to put each place with the names in a sheet ..
    According to the sample : there are three places so I need to create three worksheets and put the results with the header in each sheet in cell B7
    for example : after creating the three sheets : the first sheet would be named after (i.e Place1) and put the related results in B7
    and the same steps for the two other sheets
    Thanks advanced

    Note: If you are annoyed of the last request .. you may stop and don't offer more help .. as I am very embarrassed from you

  19. #19
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Distribute names randomly

    If you think that I am annoyed you would be wrong. My single goal is to help people and learn something along the way myself. Your English language is far better than my any other language besides English so don't worry about that. Language issues can be a cause for mis-communicaton but that happens anyway. e.g. I find problems when people mix terms like Names when they mean their name values in their column of people names but I thought they meant Named Ranges as Excel defines Names. This is where the example workbook can help.

    As a long thread goes on and the OP (original poster) asks for more requirements, it can cause a thread to be long and lose interest for some. I usually recommend a new thread with a reference link to the old one. Some moderators like that and some do not. I know that when I look to see if others need help, if there are 0 responses, I look at those first. If just a few posts and the subject line is interesting, I might look at those. If there are many replies to a post even if interesting, I seldom look at those at all as I visit maybe 5 forums each day, multiple times.

    For your latest request, it might be best to post a before and after manually marked up file in a workbook. Some OP's just post workbooks and say, see the workbook for what I want. That can work if the OP marks it up well. Some helpers will not even open a workbook if they don't know what is required before doing that. I recommend doing both.

  20. #20
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    Thank you very much for reply ..
    Here's a sample workbook : Sheets Place1 / Palce2 / Place3 are the expected results (They would be created .. not existing)
    Attached Files Attached Files

  21. #21
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    Based on the first file (again) :

    Please Login or Register  to view this content.

  22. #22
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Distribute names randomly

    That's fascinating .. awesome .. wonderful
    Thanks a lot for all great and incredible help (really incredible solutions)
    You are UNIQUE ..
    Best Regards

  23. #23
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Distribute names randomly

    You are welcome. Maybe because I use collection object too much.


    Regards

+ 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. Distribute names to affiliations
    By Taisir in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-24-2014, 11:04 PM
  2. Randomly Pick Names?
    By racefan91 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2014, 02:15 AM
  3. Randomly Assigning Names
    By kevinclark100 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-26-2013, 03:36 PM
  4. How can I distribute the balance data to the following date randomly.
    By sasgapatan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-23-2012, 04:21 AM
  5. Excel 2007 : Button to auto distribute randomly
    By patrizzull in forum Excel General
    Replies: 5
    Last Post: 01-03-2011, 11:12 PM
  6. select names randomly
    By jroque in forum Excel General
    Replies: 1
    Last Post: 01-26-2005, 08:40 PM
  7. How to randomly distribute rows from sheet 1 to sheet 2 & 3 with V
    By luk_sr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2005, 03:06 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