salut Rénato
Oufs soit patience par contre
Sub Tournoi()
Range("C6:H125").ClearContents
Dim A(6) As Byte
Dim Total(6) As Byte
Dim I As Byte
Dim K As Byte
Dim Ligne As Byte
Dim Deplacement As Byte
Dim Cellule As Range
Dim Test As Byte
For K = 1 To 40
Application.ScreenUpdating = True
Cells(1, 1) = 40 - K
Application.ScreenUpdating = False
'Générer six joueurs sans doublons
Reprise:
Cells(3, 3) = Int(Rnd() * 40 + 1)
2:
Cells(3, 4) = Int(Rnd() * 40 + 1)
If Cells(3, 4) = Cells(3, 3) Then GoTo 2
3:
Cells(3, 5) = Int(Rnd() * 40 + 1)
If Cells(3, 5) = Cells(3, 3) Or Cells(3, 5) = Cells(3, 4) Then GoTo 3
4:
Cells(3, 6) = Int(Rnd() * 40 + 1)
If Cells(3, 6) = Cells(3, 3) Or Cells(3, 6) = Cells(3, 4) Or Cells(3, 6) = Cells(3, 5) Then GoTo 4
5:
Cells(3, 7) = Int(Rnd() * 40 + 1)
If Cells(3, 7) = Cells(3, 3) Or Cells(3, 7) = Cells(3, 4) Or Cells(3, 7) = Cells(3, 5) Or Cells(3, 7) = Cells(3, 6) Then GoTo 5
6:
Cells(3, 8) = Int(Rnd() * 40 + 1)
If Cells(3, 8) = Cells(3, 3) Or Cells(3, 8) = Cells(3, 4) Or Cells(3, 8) = Cells(3, 5) Or Cells(3, 8) = Cells(3, 6) Or Cells(3, 8) = Cells(3, 7) Then GoTo 6
'Lire le tableau avec la génération
For I = 1 To 6
A(I) = Cells(3, 2 + I)
Total(I) = 0
Next I
'Vérifier si deja plein
For I = 1 To 6
Ligne = A(1) * 3 + 3
If Cells(Ligne, 3) <> "" And Cells(Ligne + 1, 3) <> "" And Cells(Ligne + 2, 3) <> "" Then GoTo Reprise
Next I
'Vérifier pas plus de 3 fois
For Each Cellule In Range("C6:H125")
If Cellule.Value = A(1) Then Total(1) = Total(1) + 1
If Cellule.Value = A(2) Then Total(2) = Total(2) + 1
If Cellule.Value = A(3) Then Total(3) = Total(3) + 1
If Cellule.Value = A(4) Then Total(4) = Total(4) + 1
If Cellule.Value = A(5) Then Total(5) = Total(5) + 1
If Cellule.Value = A(6) Then Total(6) = Total(6) + 1
For Test = 1 To 6
If Total(Test) > 18 Then GoTo Reprise
Next Test
Next Cellule
'On récupère la génération
For I = 1 To 6
Deplacement = 0
Suite:
Ligne = A(I) * 3 + 3 + Deplacement
If Deplacement > 2 Then GoTo Fin
If Cells(Ligne, 3) = "" Then
Cells(Ligne, 3) = A(1)
Cells(Ligne, 4) = A(2)
Cells(Ligne, 5) = A(3)
Cells(Ligne, 6) = A(4)
Cells(Ligne, 7) = A(5)
Cells(Ligne, 8) = A(6)
Else
Deplacement = Deplacement + 1
GoTo Suite
End If
Fin:
Next I
Next K
Application.ScreenUpdating = True
End Sub
Reste a eliminer les doublons et sortir la liste des parties (version 1.0)
Mytå