why i search data in textbox2 data in listbox is duplicate
VBA Code:
Private Sub TextBox2_Change()
Dim sh As Worksheet
Set sh = Sheets("Company name")
Dim i As Long
Dim x As Long
Dim a As Long
Dim b As Long
Me.ListBox1.Clear
Me.ListBox1.AddItem "Code"
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = "Company name"
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = "ÃËÑʼÙéàÊÕÂÀÒÉÕ"
Me.ListBox1.Selected(0) = True
For i = 4 To sh.Range("D" & Rows.Count).End(xlUp).Row
For x = 1 To Len(sh.Cells(i, 5))
a = Me.TextBox2.TextLength
b = Me.TextBox1.TextLength
If LCase(Mid(sh.Cells(i, 5), x, a)) = Me.TextBox2 And Me.TextBox2 <> "" Then
With Me.ListBox1
.AddItem sh.Cells(i, 4)
.List(ListBox1.ListCount - 1, 1) = sh.Cells(i, 5)
.List(ListBox1.ListCount - 1, 2) = sh.Cells(i, 7)
End With
End If
Next x
Next i
End Sub