Removing "Duplicate " Listbox

Pisitju

New Member
Joined
Dec 8, 2020
Messages
20
Office Version
  1. 365
Platform
  1. Windows
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
 

Attachments

  • Capture1.JPG
    Capture1.JPG
    90.4 KB · Views: 19

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,217,124
Messages
6,134,763
Members
449,888
Latest member
webarnes99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top