Private Sub ComboBox1_Change()
Dim w As Worksheet, h&
Set w = Sheets("Auxiliaire")
w.Cells.Clear
With Sheets("Contrats").[A1].CurrentRegion
.AutoFilter 1, IIf(ComboBox1 = "", "*", ComboBox1)
.Copy w.[A1]
.AutoFilter
End With
h = w.UsedRange.Rows.Count
If h = 1 Then h = 2
w.UsedRange.Offset(1).Resize(h - 1).Name = "ListBoxList"
ListBox1.RowSource = "ListBoxList"
End Sub
Private Sub UserForm_Initialize()
Dim P As Range, i&, cw$
Set P = Sheets("Contrats").[A1].CurrentRegion
With ListBox1
.ColumnCount = P.Columns.Count
P.Columns.AutoFit
For i = 1 To .ColumnCount
cw = cw & P.Columns(i).Width * (.Width - 20) / P.Width & ";"
Next i
.ColumnWidths = cw
.ColumnHeads = True
End With
ComboBox1_Change
Set P = Sheets("Auxiliaire").[A1].CurrentRegion
If P.Rows.Count = 1 Then Exit Sub
P.Sort P(1), xlAscending, Header:=xlYes 'tri
With ComboBox1
.ColumnCount = 1
.List = P(2, 1).Resize(P.Rows.Count - 1, 2).Value 'au moins 2 éléments
For i = .ListCount - 1 To 1 Step -1
If LCase(.List(i)) = LCase(.List(i - 1)) Then .RemoveItem i 'supprime les doublons
Next
End With
ComboBox1_Change 'remet dans l'ordre initial
End Sub