Sub Num_alea2()
' nombres aléatoires de 1 à 90 avec possiblement des doublons
' mais dans chaque colonne, il n'y a aucun doublon
Dim raz, pro, tir, t(1 To 90), r(1 To 10, 1 To 10), i&, j&, aux, k&
i = Application.CountA(Range("b2:k11"))
If i = 100 Then raz = MsgBox("La grille est complète, voulez-effacer le tirage et recommencer ?", vbYesNo)
If raz = vbNo Then Exit Sub
pro = [prochain]: tir = [tirage]: i = Application.CountA(Range("b2:k11"))
If IsError([prochain]) Or IsError(tir) Or i = 0 Or i = 100 Then
Range("b2:k11").ClearContents
Randomize
For i = 1 To 90: t(i) = i: Next
For k = 1 To 10
For i = 1 To 90: j = 1 + Int(Rnd * 90): aux = t(i): t(i) = t(j): t(j) = aux: Next
For i = 1 To 10: r(i, k) = t(i): Next
Next k
ThisWorkbook.Names.Add "tirage", r
ThisWorkbook.Names.Add "prochain", 1
End If
pro = [prochain] - 1: tir = [tirage]
Range("b2:k11")(1, 1).Offset(pro Mod 10, Int(pro / 10)) = tir(1 + pro Mod 10, 1 + Int(pro / 10))
ThisWorkbook.Names.Add "prochain", [prochain] + 1
End Sub