+ Reply to Thread
Results 1 to 4 of 4

Duplicate names to an array, then make random selection

  1. #1
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Duplicate names to an array, then make random selection

    Apologies about thread title, it's difficult to narrow this question down enough to a concise description!

    I am trying to create a formula to select a name at random from an array, where each name can appear x number of times.
    The issue I have is that the Names are not split out into a list x times, rather they are held just once in a table with the number of times they should occur in the adjacent cell.

    So as an example... in cells A1:A3 I have the names Huey, Dewey and Louie. And in cells B1:B3 I have the numbers 1, 2 and 3, representing how many times each name should occur.
    The aim is for a formula to duplicate them based on the occurrence number and then get them into an array along with a linear sequence number. e.g. {1,"Huey";2,"Dewey";3,"Dewey";4,"Louie";5,"Louie";6,"Louie"}
    I can then use RANDBETWEEN to generate one of the the sequence numbers and just lookup the corresponding name.

    At least that's my thinking so far as to how I approach this. It may well be over the top and/or the wrong approach, so I'm certainly open to changing direction. I'm aware that I could use VBA to do this a lot easier than a formula, but I'd rather use a formula/s if at all possible.

    Any help or ideas welcome. Thanks.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Duplicate names to an array, then make random selection

    See attached file.

    I moved your names down one row, so I can put zero in C1 and this formula in C2:

    =B2+C1

    which when copied down gives me a cumulative count. Then I used this formula in E1:

    =IF(ROWS($1:1)>MAX(C:C),"",ROWS($1:1))

    and this one in F1:

    =IF(E1="","",INDEX(A:A,MATCH(E1-1,C:C)+1))

    and copied these down to row 10, so that you could vary the numbers slightly to verify the formulae work ok - you can copy down further if you need to.

    Hope this helps.

    Pete
    Attached Files Attached Files

  3. #3
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Duplicate names to an array, then make random selection

    in terms of a single cell calc, using A1:B3 as outlined:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    however, given use of OFFSET this is Volatile.

  4. #4
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Re: Duplicate names to an array, then make random selection

    Thanks both. I'll have a play around see what's most suitable.

+ 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. Make a random selection from list and flag to not repeat
    By gandem in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2018, 12:16 AM
  2. Make more cells with duplicate names and new phones
    By anavasis in forum Excel General
    Replies: 9
    Last Post: 08-29-2017, 10:09 AM
  3. [SOLVED] make a random selection from 5 cells in a filtered sheet
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2016, 12:55 AM
  4. [SOLVED] Array with random list of names
    By aml182 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-13-2013, 11:13 AM
  5. Hey, every genius, How to avoid duplicate items in random selection from data?
    By bryansky in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-23-2013, 11:19 PM
  6. [SOLVED] Random selection of names with no duplicates and ignoring a predetermined name list
    By iain.excel in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-16-2012, 06:51 PM
  7. Replies: 5
    Last Post: 06-22-2012, 05:28 AM

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