I'm new on this and need help with a macro I need to create. The goal is to randomly select partners for dominoes matches from a list of names.
Details:
I will have a list of players in column "B", every day could be a different amount of players and different names. In column "A" those players will have a unique number. The macro should combine those players in pairs and those partners will go against another pair both pairs randomly selected. I will specify on a cell how many times each player will play on that day. The constraints are that:
8 players x 5 games per player =40/4 players each match =10
Please let me know if you have any questions, Thanks.
This is the code i have so far:
I still can't figure how to change it so I can have more than one match per player and comply with the constraints.
Details:
I will have a list of players in column "B", every day could be a different amount of players and different names. In column "A" those players will have a unique number. The macro should combine those players in pairs and those partners will go against another pair both pairs randomly selected. I will specify on a cell how many times each player will play on that day. The constraints are that:
- No two players should play together on a team for the second time until all combinations have been used, and so on.
- No two same teams should play against each other for the second time until all combinations have been used.
- Column D: Team 1, (Player 1 number).
- Column E: Team 1, (Player 2 number).
- Column F: Team 2, (Player 1 number).
- Column G: Team 2, (Player 2 number).
8 players x 5 games per player =40/4 players each match =10
Please let me know if you have any questions, Thanks.
This is the code i have so far:
Code:
Sub SelectRandomPlayers()
Dim players()AsString, selectedPlayers(3)AsStringDim playerRange As RangeDim i AsLong, c AsLong, writeRow AsLong, ub AsLong, selectedIndex AsLong, j AsLong, ub2 AsLong
writeRow =2
Set playerRange = Range(Range("A2"), Range("A2").End(xlDown))
c = playerRange.count
ub = c -1ReDim players(ub)
For i =0To ub
players(i)= playerRange.Cells(i +1).Value2
Next i
DoFor i =0To3
ub2 = UBound(players)
selectedIndex = WorksheetFunction.RandBetween(0, ub2)
selectedPlayers(i)= players(selectedIndex)
For j = selectedIndex To ub2If j < ub2 Then players(j)= players(j +1)Next j
If ub2 >0ThenReDimPreserve players(ub2 -1)Next i
Range("D"& writeRow).Value2 = selectedPlayers(0)
Range("E"& writeRow).Value2 = selectedPlayers(1)
Range("F"& writeRow).Value2 = selectedPlayers(2)
Range("G"& writeRow).Value2 = selectedPlayers(3)
writeRow = writeRow +1LoopWhile UBound(players)>0
EndSub
I still can't figure how to change it so I can have more than one match per player and comply with the constraints.