Option Base 1
Sub Nb()
Dim i, x, z, Valo, m, Lign, Nb As Integer
Dim tabl()
x = 9 'Nombre de chiffres possibles
i = 0
ReDim tabl(x)
Resetall:
For m = 1 To x
Restart:
Randomize
Valo = Int((UBound(tabl()) - 1 + 1) * Rnd + 1)
For z = LBound(tabl()) To UBound(tabl())
If Valo = tabl(z) Then
If z <> UBound(tabl()) Then
For Nb = z + 1 To UBound(tabl()) 'Vérification du nombre de répétitions n'exede pas deux
If Valo = tabl(Nb) Then
GoTo Restart
End If
Next Nb
End If
End If
Next z
i = i + 1
tabl(i) = Valo
Next m
If tabl(1) < tabl(2) And tabl(2) < tabl(3) And tabl(3) < tabl(4) Then
Erase tabl()
GoTo Resetall
End If
If tabl(1) > tabl(2) And tabl(2) > tabl(3) And tabl(3) > tabl(4) Then
Erase tabl()
GoTo Resetall
End If
Sheets("Feuil1").Select ' Nom de la feuille où se placer
For Lign = 1 To 4 'Ligne où se placer
Range("A" & Lign).Value = tabl(Lign) 'Colonne où se placer
Next Lign
End Sub