Private Sub B_Valider_Click() 'Valider la course
Dim Col As Integer, lign As Long, k As Long, Rep As String, Concat As String
If Me.ListBox1.ListCount = 0 Then Exit Sub
If InStr(1, ListBox1.List(0), ":") = 0 Then
MsgBox "Le début de la course n'est pas valide.", vbInformation, "Erreur."
Exit Sub
End If
If Me.ComboChauffeurs.ListIndex = -1 Then
MsgBox "Choisir un chauffeur"
Exit Sub
End If
With Sheets("Planning")
lign = Me.ComboChauffeurs.ListIndex + 9
Col = Left(ListBox1.List(0), 2) - 4
If Col < 3 Then Col = 3
If Col > 13 Then Col = 13
If .Cells(lign, Col) <> "" Then
If MsgBox("Plage horaire déjà prise, voulez-vous remplacer la course initiale de " & Me.ComboChauffeurs & " ? ", vbYesNo + vbExclamation, "Attention :") = vbYes Then
For k = 0 To ListBox1.ListCount - 1
Concat = Concat & ListBox1.List(k) & Chr(10)
Next
Cells(lign, Col) = Left(Concat, Len(Concat) - 1)
Else
If MsgBox("Après la course initiale ?" & Chr(10) & Chr(10) & Cells(lign, Col), vbYesNo + vbInformation, "Position :") = vbYes Then
For k = 0 To ListBox1.ListCount - 1
Concat = Concat & ListBox1.List(k) & Chr(10)
Next
Cells(lign, Col) = Cells(lign, Col) & Chr(10) & Chr(10) & Left(Concat, Len(Concat) - 1)
Else
For k = 0 To ListBox1.ListCount - 1
Concat = Concat & ListBox1.List(k) & Chr(10)
Next
Cells(lign, Col) = Left(Concat, Len(Concat) - 1) & Chr(10) & Chr(10) & Cells(lign, Col)
End If
End If
Else
For k = 0 To ListBox1.ListCount - 1
Concat = Concat & ListBox1.List(k) & Chr(10)
Next
Cells(lign, Col) = Left(Concat, Len(Concat) - 1)
End If
End With
Remise_Zero
Me.ListBox1.Clear
Me.txtHeure.SetFocus
End Sub