Boostez vos compétences Excel avec notre communauté !
Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !
Option Explicit
Private Sub CommandButton42_Click()
Dim i As Integer
Dim num As Integer
Dim j As Integer
Application.ScreenUpdating = False
CommandButton42.Enabled = False
NP = True
For i = 1 To 9
debut:
Randomize
num = Int((41 * Rnd) + 1)
For j = 1 To UBound(tablo, 1)
If num = tablo(j) Then GoTo debut
If tablo(j) <> '' Then
If num = 1 Then
If tablo(j) = 2 Or tablo(j) = 3 Or tablo(j) = 4 Then GoTo debut
End If
If num = 2 Then
If tablo(j) = 1 Or tablo(j) = 3 Or tablo(j) = 7 _
Or tablo(j) = 6 Or tablo(j) = 5 Then GoTo debut
End If
If num = 3 Then
If tablo(j) = 1 Or tablo(j) = 4 Or tablo(j) = 8 _
Or tablo(j) = 7 Or tablo(j) = 6 Or tablo(j) = 2 Then GoTo debut
End If
If num = 4 Then
If tablo(j) = 1 Or tablo(j) = 3 Or tablo(j) = 7 _
Or tablo(j) = 8 Or tablo(j) = 9 Then GoTo debut
End If
If num = 5 Then
If tablo(j) = 10 Or tablo(j) = 11 Or tablo(j) = 12 _
Or tablo(j) = 6 Or tablo(j) = 2 Then GoTo debut
End If
If num = 6 Then
If tablo(j) = 2 Or tablo(j) = 3 Or tablo(j) = 7 _
Or tablo(j) = 13 Or tablo(j) = 12 Or tablo(j) = 11 Or tablo(j) = 5 Then GoTo debut
End If
If num = 7 Then
If tablo(j) = 2 Or tablo(j) = 3 Or tablo(j) = 4 _
Or tablo(j) = 8 Or tablo(j) = 14 Or tablo(j) = 13 Or tablo(j) = 12 Or tablo(j) = 6 Then GoTo debut
End If
If num = 8 Then
If tablo(j) = 3 Or tablo(j) = 4 Or tablo(j) = 9 _
Or tablo(j) = 15 Or tablo(j) = 14 Or tablo(j) = 13 Or tablo(j) = 7 Then GoTo debut
End If
If num = 9 Then
If tablo(j) = 4 Or tablo(j) = 16 Or tablo(j) = 15 _
Or tablo(j) = 14 Or tablo(j) = 8 Then GoTo debut
End If
If num = 10 Then
If tablo(j) = 5 Or tablo(j) = 11 Or tablo(j) = 19 _
Or tablo(j) = 18 Or tablo(j) = 17 Then GoTo debut
End If
If num = 11 Then
If tablo(j) = 5 Or tablo(j) = 6 Or tablo(j) = 12 _
Or tablo(j) = 20 Or tablo(j) = 19 Or tablo(j) = 18 Or tablo(j) = 10 Then GoTo debut
End If
If num = 12 Then
If tablo(j) = 5 Or tablo(j) = 6 Or tablo(j) = 7 _
Or tablo(j) = 13 Or tablo(j) = 21 Or tablo(j) = 20 Or tablo(j) = 19 Or tablo(j) = 11 Then GoTo debut
End If
If num = 13 Then
If tablo(j) = 6 Or tablo(j) = 7 Or tablo(j) = 8 _
Or tablo(j) = 14 Or tablo(j) = 22 Or tablo(j) = 21 Or tablo(j) = 20 Or tablo(j) = 12 Then GoTo debut
End If
If num = 14 Then
If tablo(j) = 9 Or tablo(j) = 7 Or tablo(j) = 8 _
Or tablo(j) = 15 Or tablo(j) = 23 Or tablo(j) = 22 Or tablo(j) = 21 Or tablo(j) = 13 Then GoTo debut
End If
If num = 15 Then
If tablo(j) = 16 Or tablo(j) = 9 Or tablo(j) = 8 _
Or tablo(j) = 24 Or tablo(j) = 23 Or tablo(j) = 22 Or tablo(j) = 14 Then GoTo debut
End If
If num = 16 Then
If tablo(j) = 9 Or tablo(j) = 25 Or tablo(j) = 24 _
Or tablo(j) = 23 Or tablo(j) = 15 Then GoTo debut
End If
If num = 17 Then
If tablo(j) = 10 Or tablo(j) = 18 Or tablo(j) = 16 Then GoTo debut
End If
If num = 18 Then
If tablo(j) = 17 Or tablo(j) = 10 Or tablo(j) = 11 _
Or tablo(j) = 19 Or tablo(j) = 27 Or tablo(j) = 26 Then GoTo debut
End If
If num = 19 Then
If tablo(j) = 10 Or tablo(j) = 11 Or tablo(j) = 12 _
Or tablo(j) = 20 Or tablo(j) = 28 Or tablo(j) = 27 Or tablo(j) = 26 Or tablo(j) = 18 Then GoTo debut
End If
If num = 20 Then
If tablo(j) = 13 Or tablo(j) = 11 Or tablo(j) = 12 _
Or tablo(j) = 21 Or tablo(j) = 29 Or tablo(j) = 28 Or tablo(j) = 27 Or tablo(j) = 19 Then GoTo debut
End If
If num = 21 Then
If tablo(j) = 13 Or tablo(j) = 14 Or tablo(j) = 12 _
Or tablo(j) = 22 Or tablo(j) = 30 Or tablo(j) = 29 Or tablo(j) = 28 Or tablo(j) = 20 Then GoTo debut
End If
If num = 22 Then
If tablo(j) = 13 Or tablo(j) = 14 Or tablo(j) = 15 _
Or tablo(j) = 23 Or tablo(j) = 31 Or tablo(j) = 30 Or tablo(j) = 29 Or tablo(j) = 21 Then GoTo debut
End If
If num = 23 Then
If tablo(j) = 16 Or tablo(j) = 14 Or tablo(j) = 15 _
Or tablo(j) = 24 Or tablo(j) = 31 Or tablo(j) = 30 Or tablo(j) = 32 Or tablo(j) = 22 Then GoTo debut
End If
If num = 24 Then
If tablo(j) = 25 Or tablo(j) = 16 Or tablo(j) = 15 _
Or tablo(j) = 32 Or tablo(j) = 31 Or tablo(j) = 23 Then GoTo debut
End If
If num = 25 Then
If tablo(j) = 16 Or tablo(j) = 24 Or tablo(j) = 32 Then GoTo debut
End If
If num = 26 Then
If tablo(j) = 17 Or tablo(j) = 18 Or tablo(j) = 19 _
Or tablo(j) = 27 Or tablo(j) = 33 Then GoTo debut
End If
If num = 27 Then
If tablo(j) = 18 Or tablo(j) = 19 Or tablo(j) = 20 _
Or tablo(j) = 28 Or tablo(j) = 34 Or tablo(j) = 33 Or tablo(j) = 26 Then GoTo debut
End If
If num = 28 Then
If tablo(j) = 21 Or tablo(j) = 19 Or tablo(j) = 20 _
Or tablo(j) = 29 Or tablo(j) = 35 Or tablo(j) = 34 Or tablo(j) = 27 Or tablo(j) = 33 Then GoTo debut
End If
If num = 29 Then
If tablo(j) = 21 Or tablo(j) = 22 Or tablo(j) = 20 _
Or tablo(j) = 30 Or tablo(j) = 36 Or tablo(j) = 35 Or tablo(j) = 34 Or tablo(j) = 28 Then GoTo debut
End If
If num = 30 Then
If tablo(j) = 21 Or tablo(j) = 22 Or tablo(j) = 23 _
Or tablo(j) = 31 Or tablo(j) = 37 Or tablo(j) = 36 Or tablo(j) = 35 Or tablo(j) = 29 Then GoTo debut
End If
If num = 31 Then
If tablo(j) = 22 Or tablo(j) = 23 Or tablo(j) = 24 _
Or tablo(j) = 32 Or tablo(j) = 37 Or tablo(j) = 36 Or tablo(j) = 30 Then GoTo debut
End If
If num = 32 Then
If tablo(j) = 25 Or tablo(j) = 23 Or tablo(j) = 24 _
Or tablo(j) = 31 Or tablo(j) = 37 Then GoTo debut
End If
If num = 33 Then
If tablo(j) = 26 Or tablo(j) = 27 Or tablo(j) = 28 _
Or tablo(j) = 34 Or tablo(j) = 38 Then GoTo debut
End If
If num = 34 Then
If tablo(j) = 27 Or tablo(j) = 28 Or tablo(j) = 29 _
Or tablo(j) = 35 Or tablo(j) = 39 Or tablo(j) = 38 Or tablo(j) = 33 Then GoTo debut
End If
If num = 35 Then
If tablo(j) = 28 Or tablo(j) = 29 Or tablo(j) = 30 _
Or tablo(j) = 36 Or tablo(j) = 40 Or tablo(j) = 39 Or tablo(j) = 38 Or tablo(j) = 34 Then GoTo debut
End If
If num = 36 Then
If tablo(j) = 31 Or tablo(j) = 29 Or tablo(j) = 30 _
Or tablo(j) = 37 Or tablo(j) = 40 Or tablo(j) = 39 Or tablo(j) = 35 Then GoTo debut
End If
If num = 37 Then
If tablo(j) = 31 Or tablo(j) = 32 Or tablo(j) = 30 _
Or tablo(j) = 36 Or tablo(j) = 40 Then GoTo debut
End If
If num = 38 Then
If tablo(j) = 33 Or tablo(j) = 34 Or tablo(j) = 35 _
Or tablo(j) = 39 Or tablo(j) = 41 Then GoTo debut
End If
If num = 39 Then
If tablo(j) = 34 Or tablo(j) = 35 Or tablo(j) = 36 _
Or tablo(j) = 40 Or tablo(j) = 41 Or tablo(j) = 38 Then GoTo debut
End If
If num = 40 Then
If tablo(j) = 35 Or tablo(j) = 36 Or tablo(j) = 37 _
Or tablo(j) = 39 Or tablo(j) = 41 Then GoTo debut
End If
If num = 41 Then
If tablo(j) = 38 Or tablo(j) = 39 Or tablo(j) = 40 Then GoTo debut
End If
End If
Next j
'Range('c' & i) = num
tablo(i) = num
'
Next i
'raz bouton
For i = 1 To 41
Controls('CommandButton' & i).BackColor = &H8000000F
Controls('CommandButton' & i).Caption = ''
Next i
CommandButton46.Caption = 'Afficher les ' & vbNewLine & 'lignes à 0'
'raz labels
For i = 1 To 19
Controls('Label' & i).Caption = '0'
Next i
'triche
'For i = 1 To UBound(tablo)
'Controls('CommandButton' & tablo(i)).BackColor = &HC0C0FF
'Next i
Label46 = 9
calcul
Application.ScreenUpdating = True
CommandButton42.Enabled = True
End Sub
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?