Bonjour,
Il faut mettre Trim(Id) pour la comparaison.
Et pour plus de lisibilité, effacer les textbox avec CommandButton_Nouveau_Click.
Private Sub ListBox1_Change()
Dim Nom2 As Range
Dim X As Integer
Dim Id As String
CommandButton_Nouveau_Click
For X = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(X) = True Then
Id = ListBox1.List(X)
LLigne = ListBox1.ListIndex
Exit For
End If
Next X
With ThisWorkbook.Sheets("REGISTRE DES SOUS-TRAITANTS")
For Each Nom2 In .Range("A2:M" & .[A5000].End(xlUp).Row)
If CStr(Nom2) = Trim(Id) Then
Me.TextBox2.Value = .Cells(Nom2.Row, 1)
Me.ComboBox1.Value = .Cells(Nom2.Row, 2)
Me.TextBox3.Value = .Cells(Nom2.Row, 3)
Me.TextBox4.Value = .Cells(Nom2.Row, 4)
Me.TextBox5.Value = .Cells(Nom2.Row, 5)
Me.TextBox6.Value = .Cells(Nom2.Row, 6)
Me.TextBox7.Value = .Cells(Nom2.Row, 7)
Me.TextBox8.Value = .Cells(Nom2.Row, 8)
Me.TextBox9.Value = .Cells(Nom2.Row, 9)
Me.TextBox10.Value = .Cells(Nom2.Row, 10)
Me.TextBox11.Value = .Cells(Nom2.Row, 11)
Me.TextBox12.Value = .Cells(Nom2.Row, 12)
Me.TextBox13.Value = .Cells(Nom2.Row, 13)
End If
Next
End With
End Sub
Idem pour TextBox1_Change pour l'effacement des TextBox.
Private Sub TextBox1_Change()
If Me.TextBox1 <> "" Then
CommandButton_Nouveau_Click
mots = Split(Trim(Me.TextBox1), " ")
Tbl = choix
For I = LBound(mots) To UBound(mots)
Tbl = Filter(Tbl, mots(I), True, vbTextCompare)
Next I
If UBound(Tbl) > -1 Then
Dim b(): ReDim b(1 To UBound(Tbl) + 1, 1 To Ncol)
For I = LBound(Tbl) To UBound(Tbl)
a = Split(Tbl(I), "*")
For k = 1 To Ncol: b(I + 1, k) = a(k - 1): Next k
Next I
Me.ListBox1.List = b
End If
Else
UserForm_Initialize
End If
End Sub