1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Sub Tirage_aleatoire()
Dim Valeur As String
Dim Nb_Tirage As Integer, Nb_Alea As Integer
Application.ScreenUpdating = False
Range("G11:P15").ClearContents 'on efface les précédents tirages
For i = 11 To 15 'tirage pour la semaine
For j = 2 To 6 'les valeurs à placer
Valeur = Cells(10, j)
Nb_Tirage = Cells(i, j)
For t = 1 To Nb_Tirage
Randomize 'Initialise le générateur de nombres aléatoires
Tirage_aleatoire:
Nb_Alea = Int(10 * Rnd) + 1 'Nombre aléatoire entier entre 1 et 10
If Cells(i, Nb_Alea + 6) = "" Then 'Si l'employé est libre
Cells(i, Nb_Alea + 6) = Valeur 'on y met la valeur
Else
GoTo Tirage_aleatoire 'sinon on refait un tirage aléatoire
End If
Next t
Next j
Next i
'Recupération du résultat dans le tableau
Col = 7
For i = 12 To 48 Step 4
Range(Cells(2, i), Cells(6, i)).Value = Range(Cells(11, Col), Cells(15, Col)).Value
Col = Col + 1
Next i
End Sub |
Partager