Sub Tirages()
Dim n%, lig%, i%, j%, plage As Range, sup As Range, n1%
Application.ScreenUpdating = False
n = Application.CountA(Rows(1)) 'nombre d'équipes
lig = n + 4 '1ère ligne d'écriture
Range("A" & lig & ":C65536").ClearContents
'---Détermination de tous les arrangements valides---
For i = 2 To n + 1
For j = 2 To n + 1
If Cells(i, 2) <> Cells(j, 2) And Cells(i, j + 1) <= 50 Then
Cells(lig, 1) = Cells(i, 1)
Cells(lig, 2) = Cells(j, 1)
lig = lig + 1
End If
Next
Next
'---Tri aléatoire---
Set plage = Range(Cells(n + 4, 3), Cells(lig - 1, 3))
plage.Formula = "=RAND()"
plage.Offset(, -2).Resize(, 3).Sort Key1:=plage, Order1:=xlAscending, Header:=xlNo
plage.ClearContents
'---Si une équipe est déjà inscrite, suppression de la ligne---
For i = n + 5 To lig - 1
Set plage = Range(Cells(n + 4, 1), Cells(i - 1, 2))
If Application.CountIf(plage, Cells(i, 1)) Or Application.CountIf(plage, Cells(i, 2)) Then
[COLOR="Red"]Rows(i).Resize(, 2) = ""[/COLOR]
Set sup = Union(Rows(i), IIf(sup Is Nothing, Rows(i), sup))
End If
Next
sup.Delete
Application.ScreenUpdating = True
n1 = Application.CountA(Range(Cells(n + 4, 1), "B65536"))
MsgBox "Nombre d'équipes : " & n1 & IIf(n1 = n, Chr(10) & "Toutes les équipes sont tirées.", "")
End Sub
Sub Stockage()
Dim n%
n = Application.CountA(Rows(1)) 'nombre d'équipes
Sheets("Stockage").Range("A:B").Clear
Range(Cells(n + 3, 1), "B65536").Copy Sheets("Stockage").Range("A1")
End Sub