Sub search(txt As MSForms.TextBox, Field_type As String, Col_Number As Integer)
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("VCS 2021")
If txt.Value = "" Or txt.Value = Field_type Then
MsgBox "Merci d'entrer le " & Field_type, vbCritical
Exit Sub
End If
Dim Search_range As Range
Set Search_range = sh.Range(sh.Cells(2, Col_Number), sh.Cells(Application.Rows.Count, Col_Number))
If Application.WorksheetFunction.CountIf(Search_range, "*" & txt.Value & "*") = 0 Then
MsgBox "Pas de correspondance trouvée", vbCritical
Exit Sub
End If
Dim iRow As Long
If Application.WorksheetFunction.CountIf(Search_range, txt.Value) > 0 Then
iRow = Application.WorksheetFunction.Match(txt.Value, Search_range, 0) + 1
Else
iRow = Application.WorksheetFunction.Match("*" & txt.Value & "*", Search_range, 0) + 1
End If
Me.TextBox_Zone.Value = sh.Range("A" & iRow).Value
Me.TextBox_Factory.Value = sh.Range("B" & iRow).Value
Me.TextBox_Name.Value = sh.Range("C" & iRow).Value
Me.TextBox_Surname.Value = sh.Range("D" & iRow).Value
End Sub