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 30 31 32 33 34 35 36
| Private Sub CommandButton1_Click()
Dim li As Integer, li_rep As Integer, li_rep_trouvé As Integer
Dim col_rep As Integer
Dim Nom As String, Nom_rep As String, Situation_remplaçant As String
With Worksheets("Horaire Viandes")
For li = 6 To 12 Step 3
Nom = .Cells(li, 1)
If .Cells(li, 19) = "VACANCE" Then
li_rep = li / 3 + 1 'ligne correspondante dans "Remplacement"
col_rep = 2
Do
'
' Boucle qui cherche le 1er disponible pour remplacer "Nom"
'
col_rep = col_rep + 1
Nom_rep = Worksheets("Remplacement").Cells(li_rep, col_rep)
If Nom_rep <> "" Then
Situation_remplaçant = Application.WorksheetFunction.VLookup(Nom_rep, .Range("A6:S16"), 19, False)
End If
Loop Until Situation_remplaçant = "" Or Nom_rep = ""
If Nom_rep <> "" And Situation_remplaçant = "" Then
'
' Remplaçant trouvé
'
li_rep_trouvé = Application.WorksheetFunction.Match(Nom_rep, .Range("A:A"), 0)
.Range(Cells(li, 5), Cells(li + 2, 17)).Copy Destination:= _
.Range(Cells(li_rep_trouvé, 5), Cells(li_rep_trouvé + 2, 17))
.Cells(li_rep_trouvé, 19) = "Remplacement de " & Nom
End If
End If
Next li
End With
End Sub |
Partager