Option Explicit
Const FichierOuvert = "Base.xlsx"
Const FeuilleBase = "ListePiece"
Private Sub TextBox1_Change()
Dim temp, Vals, N As Long, i As Long
temp = LCase(Me.TextBox1)
On Error GoTo Err_Fichier
With Workbooks(FichierOuvert).Sheets(FeuilleBase)
On Error Resume Next
Vals = .Range(.Range("a2"), .Range("a" & .Rows.Count).End(xlUp)).Value
End With
N = UBound(Vals, 1)
Me.ListBox1.Clear
For i = 1 To N
If LCase(Vals(i, 1)) Like "*" & temp & "*" Then
Me.ListBox1.AddItem Vals(i, 1)
End If
Next
Exit Sub
Err_Fichier:
MsgBox "Erreur -> le fichier " & FichierOuvert & " n'est sans doute pas ouvert." & _
vbLf & vbLf & "Veuillez l'ouvrir svp."
End Sub
Private Sub ListBox1_Click()
[E2] = Me.ListBox1
End Sub