+ Reply to Thread
Results 1 to 10 of 10

Picking 2 names at random and not repeating them

  1. #1
    Registered User
    Join Date
    10-29-2019
    Location
    Bristol
    MS-Off Ver
    Office 365
    Posts
    6

    Smile Picking 2 names at random and not repeating them

    Hi. I have a list of 51 names at the moment and I want it to pick 2 names art random and then do the same until all have been paired with someone else. I've found a macro that will pick random names but how do I get it to them pick another 25 names that are different to pair with the previous 25 names?

    Macro used is

    Sub PickNamesAtRandom()

    Dim HowMany As Integer
    Dim NoOfNames As Long
    Dim RandomNumber As Integer
    Dim Names() As String 'Array to store randomly selected names
    Dim i As Byte
    Dim CellsOut As Long 'Variable to be used when entering names onto worksheet
    Dim ArI As Byte 'Variable to increment through array indexes

    Application.ScreenUpdating = False

    HowMany = Range("C1").Value
    CellsOut = 2

    ReDim Names(1 To HowMany) 'Set the array size to how many names required
    NoOfNames = Application.CountA(Range("A:A")) - 1 ' Find how many names in the list
    i = 1

    Do While i <= HowMany
    RandomNo:
    RandomNumber = Application.RandBetween(2, NoOfNames + 1)
    'Check to see if the name has already been picked
    For ArI = LBound(Names) To UBound(Names)
    If Names(ArI) = Cells(RandomNumber, 1).Value Then
    GoTo RandomNo
    End If
    Next ArI
    Names(i) = Cells(RandomNumber, 1).Value ' Assign random name to the array
    i = i + 1
    Loop

    'Loop through the array and enter names onto the worksheet
    For ArI = LBound(Names) To UBound(Names)

    Cells(CellsOut, 2) = Names(ArI)
    CellsOut = CellsOut + 1

    Next ArI

    Application.ScreenUpdating = True

    End Sub

    Any help is appreciated!

  2. #2
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Picking 2 names at random and not repeating them

    An attachment would make life easier as per the yellow barrier

    but if the names are in column A in b put rand() this gives you a random number between 0 and 1

    then you can eeither copy these formula as values on top of themselves so they do not change

    Then either sort your list by the random values or use a formula to do your grouping

  3. #3
    Registered User
    Join Date
    10-29-2019
    Location
    Bristol
    MS-Off Ver
    Office 365
    Posts
    6

    Re: Picking 2 names at random and not repeating them

    The information in the sheet has names and emails address therefore I can't attach it.

    I already use that but it duplicates the pairs which I don't want. I have to do a lot of manual work to then make sure there are no duplicates

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,309

    Re: Picking 2 names at random and not repeating them

    Help us to help you.
    Supply a workbook with a sheet with 51 individual names.
    Nobody is going to think up and enter 51 names before they start to give you a clue.
    torachan.

  5. #5
    Registered User
    Join Date
    10-29-2019
    Location
    Bristol
    MS-Off Ver
    Office 365
    Posts
    6

    Re: Picking 2 names at random and not repeating them

    Sorry But it wont allow me to attach a sheet with 52 names on it.

    Richard
    Steve
    Fiona
    James
    Peter
    Matt
    Richard
    Clare
    sophia
    Dave
    Alasdair
    Ashley
    Pat
    Sonya
    Louis
    Ben
    Lisa
    Stu
    Fay
    Ruth
    oliver
    Ed
    Phil
    Mark
    Alice
    Ekaterina
    Tracey
    Stuart
    Kevin
    Christopher
    Martin
    Ryan
    Ricardo
    Philippa
    Mary
    Madhuri
    Jean
    David
    Nikki
    Sally
    Sally
    Richard
    alex
    Richard
    Joanna
    Paul
    Bradley
    Ben
    Chris
    Jahed
    Caroline

  6. #6
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Picking 2 names at random and not repeating them

    perhaps the below, although attaching as per the yellow banner would be better
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Picking 2 names at random and not repeating them

    Hi nkw2306,

    We don't really need the names as the following randomly picks the row numbers in the range and links back to that number:

    Please Login or Register  to view this content.
    Please ensure you wrap any future code you post with the appropriate tags as I have done.

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  8. #8
    Registered User
    Join Date
    10-29-2019
    Location
    Bristol
    MS-Off Ver
    Office 365
    Posts
    6

    Re: Picking 2 names at random and not repeating them

    Thank you Robert. That works perfectly!

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,588

    Re: Picking 2 names at random and not repeating them

    This assumes Names are from A1 down.
    Output from C2:D2 down.
    Please Login or Register  to view this content.
    Edit:
    Now ub = (UBound(a) + 1) \ 2, was ub = UBound(a) \ 2
    Last edited by jindon; 04-17-2020 at 08:45 AM.

  10. #10
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,309

    Re: Picking 2 names at random and not repeating them

    with a list of names.

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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] Move Repeating and Non-Repeating Names into separated columns
    By aaaaa34 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-23-2019, 03:02 PM
  2. [SOLVED] Picking Random Names From a List
    By EdWoods in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-18-2018, 09:48 PM
  3. Replies: 7
    Last Post: 12-05-2016, 10:23 AM
  4. picking a random cell from the visible
    By Anders Knudsen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-04-2013, 04:46 AM
  5. Random Names and Numbers (non-repeating)
    By mitchp in forum Excel General
    Replies: 5
    Last Post: 01-15-2011, 10:29 PM
  6. Picking random cell from range
    By Chris424 in forum Excel General
    Replies: 2
    Last Post: 01-13-2009, 04:44 PM
  7. random non-repeating names
    By rivet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-18-2005, 10:06 AM

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