Dim tablo
Dim LTO As ListObject
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Listefiltrée ListBox1, TextBox1.Value, 1
End Sub
Private Sub UserForm_Activate()
reliste Range("Bdd").ListObject, ListBox1
End Sub
Sub reliste(LO As ListObject, lst)
Dim i&
With Range(LO.Name): tablo = .Resize(.Rows.Count + 2, .Columns.Count + 1).Value: Set LTO = LO: End With
For i = 1 To UBound(tablo): tablo(i, UBound(tablo, 2)) = i: Next
lst.List = tablo
For i = lst.ListCount - 1 To 0 Step -1
If lst.List(i, 0) = "" Then lst.RemoveItem (i)
Next
End Sub
Sub Listefiltrée(Lbox, valeur, Optional col& = -1)
Dim tbl(), a&, i&, c&
If col = -1 Then col = LBound(tablo, 2)
For i = LBound(tablo) To UBound(tablo)
If LCase(tablo(i, col)) Like LCase(valeur) & "*" Then
a = a + 1: ReDim Preserve tbl(LBound(tablo, 2) To UBound(tablo, 2), 1 To a):
For c = LBound(tablo, 2) To UBound(tablo, 2): tbl(c, a) = tablo(i, c): Next
End If
Next
If a = 0 Or valeur = "" Then
'*******************************
'Fonctionnement au choix pour la non correspondance
Lbox.Clear: Exit Sub ' aucune correspondence la liste est vide
'ou
'reliste LTO, Lbox ' aucune correspondance alors tout
'********************************
Else
tbl = Application.Transpose(tbl)
If a > 1 Then Lbox.List = tbl Else If a > 0 Then Lbox.Column = tbl
End If
End Sub