Bonsoir Hervé
Je te félicite pour ton 1000ième anniversaire. Que dis-je, je crois que je mélange 2 fils en même temps.
Pour ton problème, et bien je n'aurais jamais cru pouvoir te refiler quelque chose de valable pour toi. Une idée m'est venu, si il y a des malin qui s'amuse a cliquer plusieurs fois le bouton (sensation de déjà vue) et bien il sagit tout simplement de le mettre Disable tant que la routine n'est pas terminé.
Citation:
Option Explicit
PrivateSub 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) ThenGoTo debut
If tablo(j) <> '' Then
If num = 1 Then
If tablo(j) = 2 Or tablo(j) = 3 Or tablo(j) = 4 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo debut
End If
If num = 17 Then
If tablo(j) = 10 Or tablo(j) = 18 Or tablo(j) = 16 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo debut
End If
If num = 25 Then
If tablo(j) = 16 Or tablo(j) = 24 Or tablo(j) = 32 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo 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 ThenGoTo debut
End If
If num = 41 Then
If tablo(j) = 38 Or tablo(j) = 39 Or tablo(j) = 40 ThenGoTo 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
|