Option Explicit
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub ListBox1_Click()
Dim i%, j%
Dim DerligArrivee%
Dim fDepart As Worksheet, fArrivee As Worksheet
Set fDepart = Sheets("Départ")
Set fArrivee = Sheets("Arrivée")
DerligArrivee = fArrivee.Cells(Rows.Count, 1).End(xlUp).Row
DerligArrivee = DerligArrivee + 1
ReDim a(1 To 1, 1 To 6)
For i = 0 To ListBox1.ListCount
If ListBox1.Selected(i) = True Then
For j = 0 To 5
a(1, j + 1) = ListBox1.List(i, j)
Next j
End If
Next i
If fArrivee.Range("A2") = "" Then
fArrivee.Cells(DerligArrivee - 1, 1).Resize(1, 6) = a
Else
fArrivee.Cells(DerligArrivee, 1).Resize(1, 6) = a
End If
ListBox1.Clear
Call UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
Dim i%
Dim fDepart As Worksheet, fArrivee As Worksheet
Set fDepart = Sheets("Départ")
Set fArrivee = Sheets("Arrivée")
Dim TabDep(), TabArr(), tablo
TabDep = fDepart.Range("A2:G" & fDepart.Range("A" & Rows.Count).End(xlUp).Row)
TabArr = fArrivee.Range("A2:G" & fArrivee.Range("A" & Rows.Count).End(xlUp).Row)
Set tablo = fArrivee.Range("A2:G" & fArrivee.Range("A" & Rows.Count).End(xlUp).Row)
Label1.Caption = "Rendez-vous de la journée"
Dim BD(), d
BD = tablo.Value
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbTextCompare
For i = LBound(BD) To UBound(BD)
If CDate(tablo(i, 1)) = Date Then
If Not d.exists(BD(i, 4)) Then d(BD(i, 4) & BD(i, 2)) = ""
End If
Next
For i = 1 To UBound(TabDep)
If TabDep(i, 1) = Date And Not d.exists(TabDep(i, 4) & TabDep(i, 2)) Then
ListBox1.AddItem TabDep(i, 1)
ListBox1.List(ListBox1.ListCount - 1, 1) = FormatDateTime(TabDep(i, 2), vbShortTime)
ListBox1.List(ListBox1.ListCount - 1, 2) = TabDep(i, 3)
ListBox1.List(ListBox1.ListCount - 1, 3) = TabDep(i, 4)
ListBox1.List(ListBox1.ListCount - 1, 4) = TabDep(i, 5)
ListBox1.List(ListBox1.ListCount - 1, 5) = TabDep(i, 6)
End If
Next i
Set tablo = Nothing
Set d = Nothing
With ListBox1
.Visible = True
.Left = 6
.Top = 24
.Width = 348
.ColumnCount = 6
.ColumnWidths = "60;40;40;60;70;60"
.BackColor = RGB(0, 167, 246)
.Height = ListBox1.Font.Size * ListBox1.ListCount + 2 * ListBox1.ListCount + (ListBox1.Font.Size + 2) / 4
End With
End Sub