Je ne connais pas ton nouveau classeur.
voilà ce qu'il faut modifier....
partie initialisation du userform
seul le textbox1 sera visible.
Private Sub UserForm_Initialize()
With Sheets("base")
Me.Label1.Caption = .Cells(1, 7).Value
Me.Label2.Visible = False
Me.Label3.Visible = False
Me.Label4.Visible = False
Me.TextBox2.Visible = False
Me.TextBox3.Visible = False
Me.TextBox4.Visible = False
'Me.Label2.Caption = .Cells(1, 2).Value
'Me.Label3.Caption = .Cells(1, 3).Value
'Me.Label4.Caption = .Cells(1, 4).Value
End With
End Sub
partie textbox
Private Sub TextBox1_Change()
'Call chercher(TextBox1.Value, 1) 'mis en commentaire
Call chercher(TextBox1.Value, 7) ' pour rechercher sur la colonne 7
End Sub
partie procedure de recherche
Public Sub chercher(rech, c) ' recherche d'une chaine
Dim sel As Object
Dim valide As Boolean
Dim i As Integer
Dim l As Long
Dim n As Integer
l = 2: n = 0
recherche.ListBox1.Clear
With Sheets("base")
If rech = "" Then Exit Sub
Do
Set sel = .Cells.Find(What:=rech, After:=.Cells(l, c), _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)
If sel Is Nothing Then Exit Do
If sel.Column <> c Then Exit Do
If sel.Row <= l Then Exit Do
l = sel.Row
valide = True
'partie suivante mis en commentaire ************
' For i = 1 To 4
' If recherche.Controls("TextBox" & i).Value <> "" _
' And InStr(1, LCase(.Cells(l, i).Value), LCase(recherche.Controls("TextBox" & i).Value)) = 0 Then valide = False
' Next i
'fin de section mis en commentaire ************
'si le control est le textbox1 avec un vide on fait rien
' si la colnne est vide ( en G) on fait rien
' ce qui donne...
If recherche.Controls("TextBox" & 1).Value <> "" _
And InStr(1, LCase(.Cells(l, 7).Value), LCase(recherche.Controls("TextBox" & 1).Value)) = 0 Then valide = False
'si le controle est ok on fait la concaténation des 4 colonne avec "&"
If valide Then
' ici on met en forme la recherche les lignes avec .cells(l,2).value ecrivent les valeurs de la colonne B
recherche.ListBox1.AddItem _
(.Cells(l, 7).Value & " " & _
.Cells(l, 2).Value & " " & _
.Cells(l, 3).Value & " " & _
.Cells(l, 4).Value)
recherche.ListBox1.List(n, 2) = sel.Row
n = n + 1
End If
Loop
End With
End Sub