Hello
i have a macro vb that create fixtures 1 number vs 1 number but how can i do the same but took 2 numbers instead of 1 to create 2 vs 2 fixtures ?
Thanks
i have a macro vb that create fixtures 1 number vs 1 number but how can i do the same but took 2 numbers instead of 1 to create 2 vs 2 fixtures ?
VBA Code:
Sub Main(ByVal Control As IRibbonControl)
Dim teamArray As Variant
Dim i As Long, n As Long, x As Long, p As Long, j As Integer
Dim nrow As Integer, nTeam As Integer, ncopyrow As Integer, iRow As Integer
Dim Ngame As String
imsg = MsgBox("Would you like to create a new fixture list?" & Chr(10) & "By click 'Yes' all existing fixtures and results will be erased", vbYesNo)
Application.ScreenUpdating = False
If imsg = vbNo Then
Exit Sub
End If
If Sheet1.Range("C5").Value = "" Then
MsgBox ("No teams have been entered on the Teams tab.")
Exit Sub
End If
Call Env_Var
Sheet2.Cells.ClearContents
Sheet3.Cells.Delete
If Range("Teams").Count Mod 2 <> 0 Then
Range("Col_Team").Offset(Range("Teams").Count + 1, 0).Value = v_Team
Range("Col_Team").Offset(Range("Teams").Count, -1).Value = Range("Col_Team").Offset(Range("Teams").Count - 1, -1).Value + 1
Range("Col_Team").Offset(Range("Teams").Count, 1).Value = v_Venue
End If
teamArray = Range("Teams")
teamArray = ShuffleArrayInPlace(teamArray)
nrow = UBound(teamArray) / 2
nTeam = UBound(teamArray)
ncopyrow = nrow
For i = LBound(teamArray) To UBound(teamArray) / 2
Sheet2.Cells(i, "A") = teamArray(i, 1)
Next i
For n = (UBound(teamArray) / 2) + 1 To UBound(teamArray)
Sheet2.Cells((n - (UBound(teamArray) / 2)), "B") = teamArray(n, 1)
Next n
Sheet2.Range("A1:B" & nrow).Copy Sheet3.Range("A1")
ncopyrow = nrow + 2
For x = 1 To nTeam - 2
If x Mod 2 = 0 Then
Call Even
Else
Call Odd
End If
Sheet2.Range("A1:B" & nrow).Copy Sheet3.Range("A" & ncopyrow)
ncopyrow = ncopyrow + nrow + 1
Next x
If v_Play > 1 Then
'CODE HERE
For p = 2 To v_Play
iRow = iRow + ncopyrow
If p Mod 2 = 0 Then
'Even
Sheet3.Range("B1:B" & ncopyrow - 2).Copy Sheet3.Range("A" & iRow)
Sheet3.Range("A1:A" & ncopyrow - 2).Copy Sheet3.Range("B" & iRow)
Else
Sheet3.Range("A1:B" & ncopyrow - 2).Copy Sheet3.Range("A" & iRow - 1)
iRow = iRow - 2
End If
'Odd
Next p
End If
Sheet2.Cells.ClearContents
Format_Fixtures ((Sheet3.Range("A1048576").End(xlUp).Row))
Sheet3.Select
Application.ScreenUpdating = True
End Sub
Sub League_Table(ByVal Control As IRibbonControl)
Dim iRow As Integer, Rslt As Integer, aRow As Integer
Dim c As Range, xTable As Range
Dim z As Range, IRange As Range
Dim H As Integer, A As Integer
Dim p As Range
Dim hTeam As String, aTeam As String
Dim hScore As Integer, aScore As Integer, aBouns As Integer, hBonus As Integer
Dim nOrd As Integer, nVal As Integer, i As Integer
Application.ScreenUpdating = False
iRow = Sheet3.Range("B1048576").End(xlUp).Row
Call Env_Var
Call Format_League
For Each c In Sheet3.Range("B5:B" & iRow)
hTeam = c.Text
aTeam = c.Offset(0, 4).Text
hScore = c.Offset(0, 1).Value
aScore = c.Offset(0, 3).Value
aBonus = 0
hBonus = 0
If InStr(1, hTeam, "Fixture") = 0 Then
H = Sheet6.Range("C:C").Find(hTeam).Row
A = Sheet6.Range("C:C").Find(aTeam).Row
If c.Offset(0, 1).Value = "" And c.Offset(0, 3).Value = "" Then
If Sheet6.Cells(H, NX).Value = "" And Sheet6.Cells(A, NX).Value = "" Then
Sheet6.Cells(H, NX).Value = "(H) v " & aTeam
Sheet6.Cells(A, NX).Value = "(A) v " & hTeam
End If
Else
With Sheet6
'Pl Home
.Cells(H, Pl).Value = .Cells(H, Pl).Value + 1
'Pl Away
.Cells(A, Pl).Value = .Cells(A, Pl).Value + 1
'Bonus Point for Score
If Range("at_BP_Score_Op").Value = "" Or Range("at_BP_Score_Score").Value = "" Or Range("at_BP_Score_Points").Value = "" Then
Else
If Range("at_BP_Score_Op").Value = "Greater than" Then
If hScore > Range("at_BP_Score_Score").Value Then hBonus = hBonus + Range("at_BP_Score_Points").Value
If aScore > Range("at_BP_Score_Score").Value Then aBonus = aBonus + Range("at_BP_Score_Points").Value
Else
If hScore >= Range("at_BP_Score_Score").Value Then hBonus = hBonus + Range("at_BP_Score_Points").Value
If aScore >= Range("at_BP_Score_Score").Value Then aBonus = aBonus + Range("at_BP_Score_Points").Value
End If
End If
If hScore > aScore Then
'Wins Home
.Cells(H, W).Value = .Cells(H, W).Value + 1
.Cells(H, FM).Value = Left(.Cells(H, FM).Value, v_From) & "W"
If Range("at_BP_Win_Op").Value = "" Or Range("at_BP_Win_Score").Value = "" Or Range("at_BP_Margin").Value = "" Then
Else
If Range("at_BP_Win_Op").Value = "Greater than" Then
If (hScore - aScore) > Range("at_BP_Win_Score").Value Then hBonus = hBonus + Range("at_BP_Margin").Value
Else
If (hScore - aScore) >= Range("at_BP_Win_Score").Value Then hBonus = hBonus + Range("at_BP_Margin").Value
End If
End If
End If
If aScore > hScore Then
'Wins Away
.Cells(A, W).Value = .Cells(A, W).Value + 1
.Cells(A, FM).Value = Left(.Cells(A, FM).Value, v_From) & "W"
If Range("at_BP_Win_Op").Value = "" Or Range("at_BP_Win_Score").Value = "" Or Range("at_BP_Margin").Value = "" Then
Else
If Range("at_BP_Win_Op").Value = "Greater than" Then
If (aScore - hScore) > Range("at_BP_Win_Score").Value Then aBonus = aBonus + Range("at_BP_Margin").Value
Else
If (aScore - hScore) >= Range("at_BP_Win_Score").Value Then aBonus = aBonus + Range("at_BP_Margin").Value
End If
End If
End If
If hScore = aScore Then
'Draws Home
.Cells(H, D).Value = .Cells(H, D).Value + 1
.Cells(H, FM).Value = Left(.Cells(H, FM).Value, v_From) & "D"
End If
If aScore = hScore Then
'Draws Away
.Cells(A, D).Value = .Cells(A, D).Value + 1
.Cells(A, FM).Value = Left(.Cells(A, FM).Value, v_From) & "D"
End If
If hScore < aScore Then
'Losses Home
.Cells(H, L).Value = .Cells(H, L).Value + 1
.Cells(H, FM).Value = Left(.Cells(H, FM).Value, v_From) & "L"
End If
If aScore < hScore Then
'Losses Away
.Cells(A, L).Value = .Cells(A, L).Value + 1
.Cells(A, FM).Value = Left(.Cells(A, FM).Value, v_From) & "L"
End If
'Goals For Home
.Cells(H, GF).Value = .Cells(H, GF).Value + hScore
'Goals Against Home
.Cells(H, GA).Value = .Cells(H, GA).Value + aScore
'Goals For Away
.Cells(A, GF).Value = .Cells(A, GF).Value + aScore
'Goals Against Away
.Cells(A, GA).Value = .Cells(A, GA).Value + hScore
'Goal Difference Home
.Cells(H, GD).Value = .Cells(H, GF).Value - .Cells(H, GA).Value
'Goal Difference Away
.Cells(A, GD).Value = .Cells(A, GF).Value - .Cells(A, GA).Value
'Points Home
.Cells(H, Pts).Value = (.Cells(H, W).Value * v_Win) + (.Cells(H, D).Value * v_Draw) + (.Cells(H, L).Value * v_Loss) + hBonus
'Points Away
.Cells(A, Pts).Value = (.Cells(A, W).Value * v_Win) + (.Cells(A, D).Value * v_Draw) + (.Cells(A, L).Value * v_Loss) + aBonus
End With
End If
End If
Next c
'Sort the Table
Set xTable = Sheet6.Range(Sheet6.Cells(4, 2), Sheet6.Cells(ntbl, 13))
If Range("P_Order_Value").Value = "" Or Range("P_Order_Value").Offset(0, 1).Value = "" Then
Set IRange = Range("P_Order_Df")
Else
Set IRange = Range("P_Order")
End If
Sheet6.Sort.SortFields.Clear
For Each z In IRange
If z.Value = "" Or z.Offset(0, 1).Value = "" Then
Else
nVal = Application.WorksheetFunction.VLookup(z.Value, Range("LIST"), 2, 0)
nOrd = Application.WorksheetFunction.VLookup(z.Offset(0, 1).Value, Range("Order"), 2, 0)
Sheet6.Sort.SortFields.Add Key:=Sheet6.Range( _
Sheet6.Cells(5, nVal), Sheet6.Cells(ntbl, nVal)), SortOn:=xlSortOnValues, Order:=nOrd, DataOption:= _
xlSortNormal
End If
Next z
With Sheet6.Sort
.SetRange xTable
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
aRow = Sheet6.Range("C1048576").End(xlUp).Row
For Each p In Sheet6.Range("C5:C" & aRow)
i = i + 1
p.Offset(0, -1).Value = i
For j = 1 To 8
If p.Offset(0, j).Value = "" Then p.Offset(0, j).Value = 0
Next j
Next p
Application.ScreenUpdating = True
End Sub
Thanks