Tournament Brackets

upmyallee

New Member
Joined
Sep 14, 2020
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
I'm trying to make tournament brackets of individuals in different teams. I am trying to randomize the brackets to start, and have been able to do so by using =rand() function along with vlookups. The only issue, is sometimes randomizing matches certain teammates up together in the first round. Is there a way to randomize it with stipulation that team members do not get paired together at first?

It is a list of 32 players, and each pair can not be from the same team to start.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Well, formulas are almost Greek to me, but this seemed interesting enough to give it a shot. It does seem to work! :)
Just press F9 to recalculate until "Ok" magically appears. This will generate a unique list with no consecutive Odd/Even pairs.
You could surely combine some of the steps into a single formula, but I thought it easier to understand by leaving the parts as is.

Book1
ABCDEFGH
111Player 1, Pair 10.84949563FALSEOk
221Player 2, Pair 10.99560711FALSE
332Player 3, Pair 20.0884613015FALSE
442Player 4, Pair 20.532909158FALSE
553Player 5, Pair 30.4719211910FALSE
663Player 6, Pair 30.3446652211FALSE
774Player 7, Pair 40.94650842FALSE
884Player 8, Pair 40.81891474FALSE
995Player 9, Pair 50.488377168FALSE
10105Player 10, Pair 50.583654126FALSE
11116Player 11, Pair 60.4521612010FALSE
12126Player 12, Pair 60.67194895FALSE
13137Player 13, Pair 70.3350622312FALSE
14147Player 14, Pair 70.88178953FALSE
15158Player 15, Pair 80.486449179FALSE
16168Player 16, Pair 80.1024732915FALSE
17179Player 17, Pair 90.3330872412FALSE
18189Player 18, Pair 90.2416912613FALSE
191910Player 19, Pair 100.631173105FALSE
202010Player 20, Pair 100.0400943216FALSE
212111Player 21, Pair 110.477171189FALSE
222211Player 22, Pair 110.3212322513FALSE
232312Player 23, Pair 120.548122147FALSE
242412Player 24, Pair 120.9545821FALSE
252513Player 25, Pair 130.76794384FALSE
262613Player 26, Pair 130.1210082814FALSE
272714Player 27, Pair 140.95053532FALSE
282814Player 28, Pair 140.392872111FALSE
292915Player 29, Pair 150.592773116FALSE
303015Player 30, Pair 150.0705293116FALSE
313116Player 31, Pair 160.1427842714FALSE
323216Player 32, Pair 160.577739137FALSE
Players
Cell Formulas
RangeFormula
D1:D32D1=RAND()
E1:E32E1=RANK(D1,$D$1:$D$32)
F1:F32F1=VLOOKUP(E1,$A$1:$B$32,2,FALSE)
G1:G32G1=IF(AND(ISODD(F1),COUNTIF($E$1:$E$32,E1)=1),E2-E1=1)
H1H1=IF(ISNA(MATCH(TRUE,G1:G32,0)),"Ok","Not Ok")
 
Upvote 0
Just curious if there was a way to do it without having it to randomize until it all fits. We have teams of 3 people and some teams that don't get in it at all. I'll try to get the list of people and names together for test sample. This might work. I'll try it next week.

Thank you!
 
Upvote 0
How about this?

2020092015 MXL Bracket (Autosaved).xlsm
ABCD
1PlayerTeamMatchups
2Player 1Team 1Team 3 - Player 1 vs Team 2 - Player 2
3Player 2Team 1Team 3 - Player 2 vs Team 2 - Player 3
4Player 3Team 1Team 3 - Player 3 vs Team 1 - Player 3
5Player 1Team 2Team 4 - Player 1 vs Team 2 - Player 1
6Player 2Team 2Team 4 - Player 2 vs Team 1 - Player 2
7Player 3Team 2Team 4 - Player 3 vs Team 1 - Player 1
8Player 1Team 3
9Player 2Team 3
10Player 3Team 3
11Player 1Team 4
12Player 2Team 4
13Player 3Team 4
Sheet1


VBA Code:
Sub BRACKETS()
Dim r As Range:         Set r = Range("Table1")
Dim AR() As Variant:    AR = r.Value2
Dim AL As Object:       Set AL = CreateObject("System.Collections.ArrayList")
Dim Grp1 As Object:     Set Grp1 = CreateObject("System.Collections.ArrayList")
Dim Grp2 As Object:     Set Grp2 = CreateObject("System.Collections.ArrayList")
Dim Res As Object:      Set Res = CreateObject("System.Collections.ArrayList")

For i = LBound(AR) To UBound(AR)
    If Not AL.contains(AR(i, 2)) Then AL.Add AR(i, 2)
Next i

StoG AL, Grp1, Grp2, AR()

For Each Plyr In Grp1
    RPOS = Application.WorksheetFunction.RandBetween(0, Grp2.Count - 1)
    OPP = Grp2.Item(RPOS)
    Res.Add Plyr & " vs " & OPP
    Grp2.Remove OPP
Next Plyr

Range("D2").Resize(Res.Count, 1) = Application.Transpose(Res.ToArray())

End Sub

Sub StoG(AL As Object, Grp1 As Object, Grp2 As Object, AR() As Variant)
Dim Pivot As Integer: Pivot = Int((AL.Count - 1) / 2)
Dim HF As Object: Set HF = CreateObject("System.Collections.ArrayList")
Dim r As Integer

For a = 0 To Pivot
    r = Application.WorksheetFunction.RandBetween(0, AL.Count - 1)
    HF.Add AL.Item(r)
    AL.Remove r
Next a

For i = LBound(AR) To UBound(AR)
    If HF.contains(AR(i, 2)) Then
        Grp1.Add Join(Array(AR(i, 2), AR(i, 1)), " - ")
    Else
        Grp2.Add Join(Array(AR(i, 2), AR(i, 1)), " - ")
    End If
Next i

End Sub
 
Upvote 0
The code looks good to me only based upon my limited C# Coding class I took in college. However, I'm am seem to be a newbie when it comes to Excel. I'm getting an error that says "ActiveX component can't create object." I was able to figure out I believe that the first table needed to be named as Table1. But I can't seem to figure out what to do about AL.

Thank you
 
Upvote 0
Oh, I see you're on a Mac. That explains why the VBA failed. Also, Eww.

Either way here's a formula solution. It takes it bit of setup but works well.

Book2
ABCDEFGHIJKLMNO
1TeamsIDRRankGroupTeamPlayerGroupRRankLinkOppTeamOPP
2Team 110.55589520Team 1Player 100.463512410Team 4Player 1
3Team 220.58523610Team 1Player 200.52429939Team 3Player 3
4Team 330.12278141Team 1Player 300.01921868Team 3Player 2
5Team 440.18884531Team 2Player 100.776985111Team 4Player 2
6Team 2Player 200.774473212Team 4Player 3
7Team 2Player 300.27362557Team 3Player 1
8Team 3Player 110.0378156Team 2Player 3
9Team 3Player 210.01188563Team 1Player 3
10Team 3Player 310.08761332Team 1Player 2
11Team 4Player 110.07357741Team 1Player 1
12Team 4Player 210.53373914Team 2Player 1
13Team 4Player 310.23065825Team 2Player 2
Sheet1
Cell Formulas
RangeFormula
B2:B5B2=ROWS($A$1:A1)
C2:C5,K2:K13C2=RAND()
D2:D5D2=RANK(C2,$C$2:$C$5)
E2:E5E2=IF(D2<INT(ROWS($A$2:$A$5)/2)+1,0,1)
J2:J13J2=INDEX($E$2:$E$5,MATCH(H2,$A$2:$A$5,0))
L2:L13L2=COUNTIFS($J$2:$J$13,J2,$K$2:$K$13,">"&K2)+1
M2:M13M2=MATCH(L2,IF($J$2:$J$13<>J2,$L$2:$L$13),0)
N2:O13N2=INDEX(H$2:H$13,$M2)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Here is another way using Power Query.

Team Rank PQ.xlsx
ABCDEF
1TeamsTeamsPlayersOpp TeamOpp Player
2Team 1Team 1Player 1Team 5Player 3
3Team 2Team 1Player 2Team 2Player 1
4Team 3Team 1Player 3Team 16Player 1
5Team 4Team 6Player 1Team 3Player 1
6Team 5Team 6Player 2Team 4Player 2
7Team 6Team 6Player 3Team 9Player 1
8Team 7Team 7Player 1Team 11Player 3
9Team 8Team 7Player 2Team 20Player 2
10Team 9Team 7Player 3Team 14Player 3
11Team 10Team 8Player 1Team 9Player 2
12Team 11Team 8Player 2Team 20Player 1
13Team 12Team 8Player 3Team 14Player 1
14Team 13Team 10Player 1Team 5Player 2
15Team 14Team 10Player 2Team 14Player 2
16Team 15Team 10Player 3Team 2Player 3
17Team 16Team 12Player 1Team 19Player 3
18Team 17Team 12Player 2Team 9Player 3
19Team 18Team 12Player 3Team 5Player 1
20Team 19Team 13Player 1Team 4Player 1
21Team 20Team 13Player 2Team 11Player 2
22Team 13Player 3Team 2Player 2
23Team 15Player 1Team 19Player 1
24Team 15Player 2Team 3Player 2
25Team 15Player 3Team 4Player 3
26Team 17Player 1Team 3Player 3
27Team 17Player 2Team 19Player 2
28Team 17Player 3Team 20Player 3
29Team 18Player 1Team 11Player 1
30Team 18Player 2Team 16Player 3
31Team 18Player 3Team 16Player 2
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index0 = Table.AddIndexColumn(Source, "Index", 0, 1),
    RL = Table.FromList(List.Random(Table.RowCount(Index0)), Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Index1 = Table.AddIndexColumn(RL, "Index", 0, 1),
    Merge = Table.NestedJoin(Index0,{"Index"},Index1,{"Index"},"Added Index",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "Added Index", {"Column1"}, {"Column1"}),
    Sort = Table.Sort(Expand,{{"Column1", Order.Ascending}}),
    Rank = Table.AddIndexColumn(Sort, "Rank", 0, 1),
    Sort1 = Table.Sort(Rank,{{"Index", Order.Ascending}}),
    RC = Table.RemoveColumns(Sort1,{"Index", "Column1"}),
    Groups = Table.AddColumn(RC, "Group", each if [Rank] < Int64.From(Table.RowCount(Sort1) / 2) then 0 else 1),
    GroupedRows = Table.Group(Groups, {"Group"}, {{"Count", each _, type table}}),
    gIndex = Table.TransformColumns(GroupedRows, {{"Count", each Table.AddIndexColumn(_, "Index", 0,1)}}),
    Players = Table.TransformColumns(gIndex, {{"Count", each Table.AddColumn(_, "Players", each {"Player 1", "Player 2", "Player 3"})}}),
    pExpand = Table.TransformColumns(Players, {{"Count", each Table.ExpandListColumn(_, "Players")}}),
    rNum = Table.Buffer(Table.TransformColumns(pExpand, {{"Count", (tbl) => Table.AddColumn(tbl, "R", (rl) => List.Random(Table.RowCount(tbl)){rl[Index]})}})),
    rSort = Table.TransformColumns(rNum, {{"Count", each Table.Sort(_, "R")}}),
    rRank = Table.TransformColumns(rSort, {{"Count", each Table.AddIndexColumn(_, "gRank", 0, 1)}}),
    Link = Table.NestedJoin(rRank{0}[Count], "gRank", rRank{1}[Count], "gRank", "Link"),
    ExpandLink = Table.ExpandTableColumn(Link, "Link", {"Teams", "Players"}, {"Opp Team", "Opp Player"}),
    ROC = Table.SelectColumns(ExpandLink,{"Teams", "Players", "Opp Team", "Opp Player"}),
    Dupe = Table.DuplicateColumn(ROC, "Teams", "Teams - Copy"),
    Split = Table.SplitColumn(Dupe, "Teams - Copy", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Teams - Copy.1", "Teams - Copy.2"}),
    Type = Table.TransformColumnTypes(Split,{{"Teams - Copy.1", type text}, {"Teams - Copy.2", Int64.Type}}),
    SortRows = Table.Sort(Type,{{"Teams - Copy.2", Order.Ascending}, {"Players", Order.Ascending}}),
    RC2 = Table.RemoveColumns(SortRows,{"Teams - Copy.1", "Teams - Copy.2"})
in
    RC2
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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