Using Excel 2010
Hello, I have a code which generate within 14 teams as per selection “Win=1”, “Draw=X” & “Loss=2” if we select all 3 options for 14 teams this will produce 3*3*3*3*3*3*3*3*3*3*3*3*3*3=4782969 combinations (3^14=4782969).
In this example I have selected 2 options for each teams in this case 2 options for 14 teams this will produce 2*2*2*2*2*2*2*2*2*2*2*2*2*2=16384 combinations (2^14=16384).
Here is macro do this job and generate using 2 double option for each 16384 combinations in the columns I:V till here hope explanations are clearer.
Here is my query each team has chosen 2 options for example team1 has X & 2 this mean there is 50% possibility of draw=X…or 50% possibility of loss=2…so far this has 50% chance for both either draw or loss. This VBA has designed to generate as seems.
What I want to be modified instead between 2 options X & 2 (50% chance can be vary that X play 20% and 2 play 80%) please see the % table in range for each team Y6:AA19…I am sure this will reduce the number of combinations. Please help with this if any question I will try to answer clearer.
Regards,
Moti
Hello, I have a code which generate within 14 teams as per selection “Win=1”, “Draw=X” & “Loss=2” if we select all 3 options for 14 teams this will produce 3*3*3*3*3*3*3*3*3*3*3*3*3*3=4782969 combinations (3^14=4782969).
In this example I have selected 2 options for each teams in this case 2 options for 14 teams this will produce 2*2*2*2*2*2*2*2*2*2*2*2*2*2=16384 combinations (2^14=16384).
Here is macro do this job and generate using 2 double option for each 16384 combinations in the columns I:V till here hope explanations are clearer.
Here is my query each team has chosen 2 options for example team1 has X & 2 this mean there is 50% possibility of draw=X…or 50% possibility of loss=2…so far this has 50% chance for both either draw or loss. This VBA has designed to generate as seems.
What I want to be modified instead between 2 options X & 2 (50% chance can be vary that X play 20% and 2 play 80%) please see the % table in range for each team Y6:AA19…I am sure this will reduce the number of combinations. Please help with this if any question I will try to answer clearer.
Regards,
Moti
Generate 1X2 Combinations By Percentage.xlsm | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | |||
1 | |||||||||||||||||||||||||||||
2 | |||||||||||||||||||||||||||||
3 | Teams | Fill Bettinng 1X2 | Prediction | Teams | Fill Bettinng 1X2 | ||||||||||||||||||||||||
4 | Teams | Win | Draw | Loss | Options | Teams | Win | Draw | Loss | ||||||||||||||||||||
5 | Teams | 1 | X | 2 | S, D, T | S.N | Team1 | Team2 | Team3 | Team4 | Team5 | Team6 | Team7 | Team8 | Team9 | Team10 | Team11 | Team12 | Team13 | Team14 | Teams | 1 | X | 2 | |||||
6 | Team1 | X | 2 | D | 1 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | 1 | 1 | X | Team1 | 20 | 80 | |||||||
7 | Team2 | 1 | X | D | 2 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | 1 | 1 | 2 | Team2 | 80 | 20 | |||||||
8 | Team3 | 1 | X | D | 3 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | 1 | X | X | Team3 | 80 | 20 | |||||||
9 | Team4 | X | 2 | D | 4 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | 1 | X | 2 | Team4 | 20 | 80 | |||||||
10 | Team5 | 1 | X | D | 5 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | X | 1 | X | Team5 | 80 | 20 | |||||||
11 | Team6 | 1 | 2 | D | 6 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | X | 1 | 2 | Team6 | 80 | 20 | |||||||
12 | Team7 | 1 | X | D | 7 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | X | X | X | Team7 | 80 | 20 | |||||||
13 | Team8 | X | 2 | D | 8 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | X | X | X | 2 | Team8 | 80 | 20 | |||||||
14 | Team9 | 1 | X | D | 9 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | 1 | 1 | X | Team9 | 80 | 20 | |||||||
15 | Team10 | X | 2 | D | 10 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | 1 | 1 | 2 | Team10 | 20 | 80 | |||||||
16 | Team11 | X | 2 | D | 11 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | 1 | X | X | Team11 | 20 | 80 | |||||||
17 | Team12 | 1 | X | D | 12 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | 1 | X | 2 | Team12 | 80 | 20 | |||||||
18 | Team13 | 1 | X | D | 13 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | X | 1 | X | Team13 | 80 | 20 | |||||||
19 | Team14 | X | 2 | D | 14 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | X | 1 | 2 | Team14 | 20 | 80 | |||||||
20 | 15 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | X | X | X | ||||||||||||||
21 | 16 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | X | 2 | X | X | 2 | ||||||||||||||
22 | Single | 0 | 1 | 17 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | 1 | 1 | X | |||||||||||
23 | Double | 14 | 16.384 | 18 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | 1 | 1 | 2 | |||||||||||
24 | Triple | 0 | 1 | 19 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | 1 | X | X | |||||||||||
25 | 20 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | 1 | X | 2 | ||||||||||||||
26 | TT:Combi | 16.384 | 21 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | X | 1 | X | ||||||||||||
27 | 22 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | X | 1 | 2 | ||||||||||||||
28 | 23 | X | 1 | 1 | X | 1 | 1 | 1 | X | 1 | 2 | X | X | X | X | ||||||||||||||
Generate 1X2 Combinations |
Cell Formulas | ||
---|---|---|
Range | Formula | |
F6:F19 | F6 | =IF(COUNTA(B6:D6)=1,"S",IF(COUNTA(B6:D6)=2,"D",IF(COUNTA(B6:D6)=3,"T",""))) |
C22 | C22 | =COUNTIF(F6:F19,"S") |
D22 | D22 | =1^C22 |
C23 | C23 | =COUNTIF(F6:F19,"D") |
D23 | D23 | =2^C23 |
C24 | C24 | =COUNTIF(F6:F19,"T") |
D24 | D24 | =3^C24 |
D26 | D26 | =D22*D23*D24 |
VBA Code:
Option Explicit
Sub GenerateMultiple_1X2_Combinations()
Sheets("Generate 1X2 Combinations").Select
Range("I6:W120000").Select
Selection.ClearContents
Range("G6").Select
Dim Ans As Boolean, Col As Collection, i As Long
Dim ColSplitted() As String
Dim ind As Integer
Set Col = New Collection
Ans = BuildLoops(BuildPreLoops, ",", Col)
If Ans Then
For i = 1 To Col.Count
ColSplitted = Split(Col(i), ",")
For ind = 0 To 13
Cells(i + 5, 9 + ind).Value = ColSplitted(ind) '(i+5=Start From Row 6)Change Output Column As desire Now it is set to 9 = I
Next ind
Next i
Else
MsgBox "Error !", vbCritical
End If
End Sub
Function BuildPreLoops() As String
Dim Rnum As Integer
Dim Cnum As Integer
BuildPreLoops = ""
For Rnum = 6 To 19
BuildPreLoops = BuildPreLoops & IIf(Cells(Rnum, 2).Text <> "", Cells(Rnum, 2).Text & IIf((Cells(Rnum, 3).Text <> "" Or Cells(Rnum, 4).Text <> ""), "+", ""), "") & _
IIf(Cells(Rnum, 3).Text <> "", Cells(Rnum, 3).Text & IIf(Cells(Rnum, 4).Text <> "", "+", ""), "") & _
IIf(Cells(Rnum, 4).Text <> "", Cells(Rnum, 4).Text, "")
BuildPreLoops = BuildPreLoops & IIf(Rnum = 19, "", ", ")
Next Rnum
End Function
Function BuildLoops(ByVal St As String, Sep As String, ByRef Col As Collection) As Boolean
Dim Ar As Variant, Ar2 As Variant, ArMain As Variant
Dim i As Long, j As Long, Ctr As Long, TempSt As String
St = Application.Substitute(St, " ", "")
Ar = Split(St, Sep)
If Not IsArray(Ar) Then Exit Function
ReDim ArMain(1 To UBound(Ar) - LBound(Ar) + 1)
For i = LBound(Ar) To UBound(Ar)
Ar2 = Split(Ar(i), "+")
Ctr = Ctr + 1
ArMain(Ctr) = Ar2
Next i
For j = LBound(ArMain(1)) To UBound(ArMain(1))
TempSt = ArMain(1)(j)
BuildString 1, ArMain, Col, TempSt
Next j
BuildLoops = True
End Function
Private Function BuildString(ByRef i As Long, ByRef ArMain As Variant, ByRef Col As Collection, ByRef TempSt As String)
Dim j As Long, St As String
St = TempSt
If i < UBound(ArMain) Then
For j = LBound(ArMain(i + 1)) To UBound(ArMain(i + 1))
TempSt = St & "," & ArMain(i + 1)(j)
BuildString i + 1, ArMain, Col, TempSt
Next j
Else
Col.Add UCase(TempSt)
End If
End Function