Removing "Duplicate Rows" Listbox

mrsec

Board Regular
Joined
Jan 28, 2016
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hello,

Why is it everytime i use the search textbox ,the listbox then comes up with multiple line with the same data?is there a way of preventing it?

VBA Code:
Private Sub TextBox1_Change()
Me.TextBox1 = Format(StrConv(Me.TextBox1, vbLowerCase))
Dim sh As Worksheet
Set sh = Sheets("Sheet1")
Dim i As Long
Dim x As Long
Dim p As Long
Me.ListBox1.Clear
Me.ListBox1.AddItem "Product ID"
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = "ARTG ID"
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = "Product Description"
Me.ListBox1.List(ListBox1.ListCount - 1, 3) = "Status"
Me.ListBox1.List(ListBox1.ListCount - 1, 4) = "Impact Start Date"
Me.ListBox1.List(ListBox1.ListCount - 1, 5) = "Impact End Date"
Me.ListBox1.List(ListBox1.ListCount - 1, 6) = "Usage End Date"


For i = 2 To sh.Range("F" & Rows.Count).End(xlUp).Row
For x = 1 To Len(sh.Cells(i, 6))
p = Me.TextBox1.TextLength

If LCase(Mid(sh.Cells(i, 6), x, p)) = Me.TextBox1 And Me.TextBox1 <> "" Then
With Me.ListBox1
.AddItem sh.Cells(i, 2)

'.List(ListBox1.ListCount - 1, 1) = sh.Cells(i, 3)
'.List(ListBox1.ListCount - 1, 2) = sh.Cells(i, 4)
.List(ListBox1.ListCount - 1, 1) = sh.Cells(i, 5)
.List(ListBox1.ListCount - 1, 2) = sh.Cells(i, 6)
.List(ListBox1.ListCount - 1, 3) = sh.Cells(i, 7)
.List(ListBox1.ListCount - 1, 4) = sh.Cells(i, 8)
.List(ListBox1.ListCount - 1, 5) = sh.Cells(i, 9)
.List(ListBox1.ListCount - 1, 6) = sh.Cells(i, 10)
'.List(ListBox1.ListCount - 1, 9) = sh.Cells(i, 11)
'.List(ListBox1.ListCount - 1, 10) = sh.Cells(i, 12)
'.List(ListBox1.ListCount - 1, 11) = sh.Cells(i, 13)
'.List(ListBox1.ListCount - 1, 12) = sh.Cells(i, 14)
'.List(ListBox1.ListCount - 1, 13) = sh.Cells(i, 15)
'.List(ListBox1.ListCount - 1, 14) = sh.Cells(i, 16)
'.List(ListBox1.ListCount - 1, 15) = sh.Cells(i, 17)
'.List(ListBox1.ListCount - 1, 16) = sh.Cells(i, 18)



End With

End If
Next x
Next i

End Sub
 

Attachments

  • duplicate.jpg
    duplicate.jpg
    120.4 KB · Views: 8

mrsec

Board Regular
Joined
Jan 28, 2016
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Ok, how about
VBA Code:
   If InStr(1, Sh.Cells(i, 2), Me.TextBox1, vbTextCompare) > 0 Or InStr(1, Sh.Cells(i, 5), Me.TextBox1, vbTextCompare) > 0 Or InStr(1, Sh.Cells(i, 6), Me.TextBox1, vbTextCompare) > 0 Or InStr(1, Sh.Cells(i, 7), Me.TextBox1, vbTextCompare) > 0 Then
smooth.its working thank you fluff.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,892
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,698
Messages
5,765,994
Members
425,322
Latest member
galaxy6623top

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
Top