Private Sub CommandButton1_Click()
Dim d1 As Object, d2 As Object, i&, x$, transfert As Boolean, lig&, j%
Set d1 = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
For i = 0 To ListBox1.ListCount - 1
d1(ListBox1.List(i)) = ListBox1.Selected(i)
Next i
For i = 0 To ListBox2.ListCount - 1
d2(ListBox2.List(i)) = ListBox2.Selected(i)
Next i
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Rows.Hidden = False 'affiche tout
For i = 2 To Cells.SpecialCells(xlCellTypeLastCell).Row
x = Cells(i, 1)
If x <> "" Then
Cells(i + 1, 1).Resize(13) = "" 'RAZ
If d1(x) Then
transfert = False
lig = i
For j = 0 To 12 Step 2
If d2(Cells(i + j, 2).Value) Then
'transfère le nom en colonne A sur la 1èree ligne visible
If Not transfert Then Cells(i + j, 1) = x: transfert = True: lig = i + j
Else
Rows(i + j).Resize(2).Hidden = True
End If
Next j
i = lig
Else
Rows(i).Resize(15).Hidden = True
End If
End If
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim d As Object, c As Range
Set d = CreateObject("Scripting.Dictionary")
Sheets("RECAP_SEMAINE").Activate
ListBox1.MultiSelect = fmMultiSelectExtended
For Each c In Columns(1).SpecialCells(xlCellTypeConstants)
If Not d.exists(c.Value) Then
d(c.Value) = ""
ListBox1.AddItem c
ListBox1.Selected(ListBox1.ListCount - 1) = True
End If
Next c
ListBox2.MultiSelect = fmMultiSelectMulti
For Each c In [B2:B14].SpecialCells(xlCellTypeConstants)
ListBox2.AddItem c
ListBox2.Selected(ListBox2.ListCount - 1) = True
Next c
End Sub