Randomly assigning Groups

cdnqte

Board Regular
Joined
Jul 14, 2004
Messages
132
I have a list of 20 golfers and I am looking for a way to create random groups of 4 based on those 20 individuals. Is there a way in excel or access to scan the 20 names and return 5 groups of 4 each week?

Any help would be appreciated!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You could try this

If your list of names is in A2:A21

In B2 put this formula

=RAND()

In C2 put this formula

=INT((ROW()-ROW(B$2)+1)/5)+1

select both B2 and C2 and copy down to row 21

Select column B and use Format > Column > Hide

Now select columns A:C and sort on column B

(Data > Sort, use either ascending or descending)

Names will be randomly sorted against group numbers.
Sort again for another random set....
 
Upvote 0
with a list in a1:a20, just enter =rand() in b1 & copy down, then sort by col b for a random order...
 
Upvote 0
You guys never fail to amaze me!

In addition to the above here is a quick visual basic macro that will get you there as well. Just place your 20 names in column A rows 1 - 20

Sub MyRandomGroups()
Dim MixIt(20), MyNames(20)
Dim K As Integer, MyCol As Integer, MyRow As Integer
Randomize Timer

For K = 1 To 20
MyNames(K) = Cells(K, 1)
Next K

For K = 1 To 20
Again:
MyRow = Int((20 * Rnd) + 1): If MyNames(MyRow) = 0 Then GoTo Again
MixIt(K) = MyNames(MyRow): MyNames(MyRow) = 0
Next K

MyCol = 2: MyRow = 1
For K = 1 To 20
Cells(MyRow, MyCol) = MixIt(K)
If K Mod 4 = 0 Then MyCol = MyCol + 1: MyRow = 0
MyRow = MyRow + 1
Next K
End Sub
 
Upvote 0
Hi, Ken,

Can you imagine how long it can take if you're going to random sort a lot of data this way? There will be a mass of extra loops.

You can use the above manual methods within code.
Example
Code:
Option Explicit
'DATA
'A B C D E
'item found     items left      loops                       possible scenario
'D              A B C E         no extra loops possible     D
'D B            A C E           1/5 chance for extra loop   B
'D B A          C E             2/5 chance for extra loop   B D A
'D B A C        E               3/5 chance for extra loop   D E
'D B A C E                      4/5 chance for extra loop   A A D B E
'this scenario looped 12 times instead of 5

'test looped 500 times the code using random pick
'items      loops
'10         30
'20         60
'30         120
'60         280
'120        650
'since the first items in larger tables will be found quickly the problem is not too big
'but anyway it's a waste

Sub random_teams()
'Erik Van Geit
'051101
'quick random sort
'COLUMN B must be empty

Dim NameList As Range
Dim ResultsTable As Range
Dim mem As Variant
Dim NR As Long

Application.ScreenUpdating = False
    Set NameList = ActiveSheet.Range("A1:A20")
    mem = NameList
    Set ResultsTable = ActiveSheet.Range("C1:G4")
    With NameList
        With .Offset(0, 1)
        .Formula = "=RAND()"
        .Value = .Value
        End With
    .Resize(.Rows.Count, 2).Sort key1:=NameList(1).Offset(0, 1), order1:=1
    .Offset(0, 1).ClearContents
    End With
    
    ResultsTable.ClearContents
    For NR = 1 To NameList.Cells.Count
    ResultsTable.Cells(NR).Value = NameList.Cells(NR, 1).Value
    Next
    
NameList = mem
Application.ScreenUpdating = True

Erase mem
End Sub
kind regards,
Erik
 
Upvote 0
Hi, Ken,

Can you imagine how long it can take if you're going to random sort a lot of data this way? There will be a mass of extra loops.

erik,

Yes sir you're absolutely correct. The code I threw together was neither pretty nor efficient ...in deed it is the antithesis of those things. That being said however, it is sufficient to handle the 20 items given in a fraction of a second as long as we're not on a 386SX ;).

Appreciate the method example you provide.

Here's another way of doing it where the loops are equal to the number of items

MaxNum = 20
For K = 1 To 20
MyRow = Int((MaxNum * Rnd) + 1)
MixIt(K) = MyNames(MyRow)
If MyRow <> MaxNum Then MyNames(MyRow) = MyNames(MaxNum)
MaxNum = MaxNum - 1
Next K

What this method does is pull the random item from the list. If the item pulled is not the last item in the list, it will take the last item and plug it into the place we just pulled from and shorten the list by one each time through the loop effectively needing only one random call per item.

Better?
 
Upvote 0
surely,

it's the best method to my sense
my method just showed how to implement the manual stuff ...

when using memory the way you did, it will be fast and no extra column is needed
you can find some other similar examples on the Board
check the board for
random sort
author: NateO
I'm sure he has posted some nice examples

best regards,
Erik
 
Upvote 0
Paddy has already given you one way to do the task one time.

For a variety of options, see
Random Selection
http://www.tushar-mehta.com/excel/newsgroups/rand_selection/index.html

Of course, what you haven't mentioned yet, and I suspect is coming next, is that as far as possible you don't want the same people playing together in different weeks. ;)

I have a list of 20 golfers and I am looking for a way to create random groups of 4 based on those 20 individuals. Is there a way in excel or access to scan the 20 names and return 5 groups of 4 each week?

Any help would be appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,359
Messages
6,124,488
Members
449,165
Latest member
ChipDude83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top