Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Find And Remove Duplicates From A ListView

Can anyone find me a code to find and remove and duplicates in a ListView? I've tried a couple but they didn't work out right. The reason why I need this is because I'm making a program that adds sites to a file and then loads them up again in the ListView.

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Find And Remove Duplicates In 1 Table?

The Access table, tblOwners, has about 200,000 owners. It's been filling for a couple of years. I just took over someone's position.

The SQL statement: SELECT DISTINCT OwnerID FROM tblOwners
returned about 180,000 records. So, I've got about 20,000 duplicates!

Question: Before I continue writing a VB .exe that uses the database, I want to remove all the duplicate records from the table.

Is there a way to clean it up?

Many thanks,

P.S. I've searched through this post on the subject and found I could place the DISTINCT records into another table, and then delete the tblOwners. Is there another way?

Remove Duplicates From Listview
I searched on this board on how to remove duplicates from a listview and got the code below but when I run it, the program crashes and ends asap. Does anyone know why or another solution?


VB Code:
Dim i As LongDim j As LongDim Current As StringFor i = ListView1.ListItems.Count To 0 Step -1   'loop the listview control  Current = ListView1.ListItems(i)  'sets the current list item  For j = ListView1.ListItems.Count To 0 Step -1  'now loop for the victims    If j <> i And ListView1.ListItems(j) = Current Then  'we found a match!      ListView1.ListItems.Remove j 'now remove it      'add more code here to execute when finding a match if you wish    End If  Next jNext i

Find Duplicates In Listview
Hi all!
This question has been posted many times i´m sure. Anyway, i have then below code which kinda works, but
if the very last item is a duplicate it doesn´t seem to find it. I tested this by sorting the listview so that the last
item in the list was not a duplicate, in that case the code found one more duplicate.

This code works great on an ordinary list, but i´m guessing that´s because the index in a list starts at 0, and in
a listview it starts at 1. So how do i go about catching that last duplicate?

Dim a As Integer, j As Integer, r As Integer

    With ExtLV1
        For a = 1 To .ListItems.Count - 1
            For j = a + 1 To .ListItems.Count - 1
                If .ListItems.Item(a) = .ListItems.Item(j) Then
                    r = r + 1
                End If
            Next j
        Next a
    End With


Edited by - Maverick2004 on 3/11/2005 12:48:20 AM

Remove Duplicates
Im 1/2 way through my project, and i need be able to remove duplicate lines from a text file - im completely stuck

i need it to be as optimised as possible
any ideas?

Need To Remove Duplicates
Anyone know of a fast/easy way to remove duplicates when importing largeamounts of information from a file?

Remove Duplicates In Excel
Hi all,

I have a excel with 1000 cells of some sort of text let say Name. I want to remove duplicates. How can I do that?

If I run a macro on it, it should remove all duplicate Names. All the names should come only once.



Remove All Duplicates From Array
First...I have an array of a number that varies...between 2 and 14. I want to be able to check if all the current number values in the array are of the same value. Example:
i have an array: Temp(6) as integer
every number in the 7 slots for temp = 9
i need way way to check if all of them are equal. But not always is the number going to be a 9, it could be anything from 1 to 14...Im kinda stumped on this...i think i would have to do some sort of
for i = 0 to ubound(temp)
if temp(i) = temp(i+1) then
if temp(i+1) = temp(i+2) then
but thats not working to well for me...can anyone help me out a bit.
If you need more info, please repond, or if it isnt clear enough, please respond.
THanks for looking


How To Remove Duplicates From A List Box?
How do I remove duplicates froma list box?

Use Of Group By To Remove Duplicates...?
Hello everyone,

I am a newb at SQL so please bare with me when I ask:
Will using a group by clause in a SQL query return only unique values in the field that the query is being grouped by?

For example If I use:

select ChipName, WaferName, Date
from tblChipInfo
group by ChipName;

Will my query only display values for WaferName and date where the ChipName is unique?

I have attempted executing a statment similar to this but am getting an error stating that the other field names in the select statement are not part of aggregate functions.

Please help...

How Do I Remove Duplicates In A Database??
I want to wash a database, and remove all duplicates in a 'contact' table. Does anyone have a query for this purpose??

Thanks in advance.

Remove Duplicates From A Listbox?

Here's an example listbox:


Hello World
Hi World
Hello World

How would I go about removing just one of the "Hello World" entries?

And this also needs to work with multiple duplicated text and without me specifying the duplicates.

Basically I need some code to check through a long listbox, find duplicates and remove them. (if there's 2 duplicates, remove 1, if theres 3 duplicates, remove 2 etc. etc.) I hope I've explained that enough for you to understand.

Remove Duplicates In Combobox
i have a combobox that displays the values in my field.....

field: Food
values: cookies, apple, spaghetti, chocolates, cookies

i want to remove the duplicates from showing in the combobox. (but it should be still in my database...) i just want to remove or disable it from showing because it is unnecessary for the user....

please help me out... thanks...

Remove Duplicates In Array
Hi guys i have some code parsing a log i have extracted the lines i want but appart from time stamp there are many duplicates. i have removed the time stamp so now they are duplicates how can i only write to a text file a line from the array if if does not allready exist? but if it does exist then move to next entry so i only end up with one off entries.

like the

21:02:06 11:16:13 john checked in
22:02:06 13:01:59 john checked in

looks like this

john checked in
john checked in

only want to write one entry to the text file and move on to the next.

thanks in advance

How Do You Remove Duplicates From A List Box?
i need to get rid of duplicate entries in a listbox? how would i go about this?

thanks alot

Remove Duplicates From ComboBox
Ok my combo boxes get filled using a database on formload.

Is there a way to see if something is already in the combo box therefore not adding it again ? (Assuming this would be slow?)

or does anyone have a quick function to remove duplicates?

Remove Duplicates From A Combo Box
this is the code for the listbox
Dim i As Long
Dim j As Long
With List1
For i = 0 To .ListCount - 1
For j = .ListCount To (i + 1) Step -1
If .List(j) = .List(i) Then
.RemoveItem j
End If
End With

End Sub

this is the best i can alter the code

Dim i As Long
Dim j As Long
With cboIUpREF
For i = 0 To .Items.Count - 1
For j = .Items.Count To (i + 1) Step -1
If .Items.Item(j) = .Items.Item(i) Then
End If
End With

the line "If .Items.Item(j) = .Items.Item(i) Then" causes an error, what could i change it to, or is there another way other removing dups from a combo box, im using

Remove Duplicates From A Combo Box
Hi, can anyone tell me how you can remove duplicate items from a combo box, iv already searched the forum and theres explanations for removing dups from only listboxes, does any one have any ideas, im using

Faster Way To Remove Duplicates??
This routine does okay if I have a few hundred items in the listview but if I have about 3,000 items, the program hangs and takes forever. Does anyone know a faster way to do this?

Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer

With ListView1
For i = 1 To .ListItems.Count
For j = .ListItems.Count To (i + 1) Step -1
If .ListItems(j) = .ListItems(i) Then
.ListItems.Remove j
End If
End With
End Sub

Remove Duplicates In A List
Here's the code:

Sub remove_dupe_list(lst As ListBox)
For a = 0 To (lst.ListCount - 1)
X$ = LCase(lst.List(a))
For b = 0 To (lst.ListCount - 1)
Y$ = LCase(lst.List(b))
If a <> b And X$ Like Y$ Then lst.RemoveItem b
Next b
Next a

End Sub

But when I use it, my program freezes. Anyone have a better code or can fix it?

Remove Duplicates From Array
hello, does anyone have a function to remove duplicates from an array (consisting of strings)?

thanks in advance

How Remove Duplicates In DataCombo?
In a form, i don't know how to remove duplicates in a data combo. My database is a database Access.

When Duplicates Exist - Remove First Instance?
I'll do my best to explain what I need to do.

Lets call this Text1:



From this textbox I want to remove the first "321" and leave the second one in the textbox. How would I go about doing this?

How Can You Remove Duplicates In A Textfile That Is 200mb Big?
Anyone know how I can do this in VB? Is it possible?

What Is The Fastest Possible Way To Remove Duplicates In A Listbox?
i haev 27000 items ina listbox.. what is the fastest method of removing duplicates?

Remove Duplicates And Sort Array
I have a large string array and I need to remove the duplicates and sort the array alphabetically.

I know I could do this through a good bit of code and some loops, but I've found more than a few times what I went about coding from scratch was already available in a function.

My best bet for fastest way to sort is through a list box invisible to the user. Is there a better way?

The only way I know of to remove the duplicates in the array would be with a nested loop searching from the beginning each time until it's determined that the string is unique and then on to the next string.

I'm guessing VB provides a quicker way.

Toolbox ICON Duplicates... Why And How To Remove Them....
This is a totally Newbie question but still I want to "clean-up" my toolbox from a particular application project. The jpeg attachment shows how my toolbox looks.... Label, option button, image and others are duplicated... why and how can I remove them (they must be there for a reason) without causing a problem to my app???



Remove Duplicates From A String Separted By Vbcrlf
Hi all.
I am having a MultilineTextbox with strings separted by vbcrlf.How can I remove the
duplicates from the string.What I do is split the string,loop through the string and find
and then remove the item.Is there any simple method avl.


Remove Duplicates Array - Text File
Hi guys i was wondering is there a way to remove duplicates in a text doc but they may not be complete duplicates example as follows

3.1.07 walking with john
4.1.07 walking with john

basically i have many repeat instances of same near same thing in a server log i want to remove the duplicate as its the same other than date stamp. also i wont know what comes after "walking with" "could be any thing here"

thanks in advance i tried removeing time stamp from each line and then removeing duplcates but with 300000 lines it seems to be never ending i am thinking that it will be never ending regardless but heres hoping

Find Duplicates And Sum
I do not do a lot of vb programming, however, I am trying to learn. I am working on automating a spreadsheet using a macro.

Each month when I run this report I dont always know how many claims there first I will need to tell the macro to only look at those lines which contain data. Then I need to look for duplicate claim numbers in column A and if duplicates are found sum the weights (in column E) of those duplicates. Here is the data I am working with:

Claim# Wt.

Here is how I would like it to look:
170015023 23,150
170015024 3,775
170015027 155,206
170015028 1,522

Thanks for any help you can provide.

Find Duplicates
i m working on a project and this project loads a text file then it displays it data innto a rich text box
but I wnat to dlete duplicates records from that text file so how can i delete
kindly tell me i m attachinfg the file


Find Duplicates In FoxPro

How can I find duplicates within text files created by FoxPro? I would like to be able to find duplicates within one file and also, comparing several files and find common duplicates. Is this possible?

Thanks so much for your help!

Find Duplicates And Move To Text Box
hi i have a program which loads a file which has a load of words (text1.text) and another (text2.text). sometimes there will be duplicates words. i am looking for some code to find the duplicates and move then to another text box i.e text3.text.

any ideas?

i will search the forums again and find any thing which may help.

Checking For Duplicates In ListView

Could someone please tell me how to check for duplicates in a ListView quickly? My first attempt was using a loop which parses the whole items and checks for duplicates, but if the ListView data gets larger, the loop would take ages to finish.
Is there any faster method?

Sebastian Mares

PS: IIRC, Thinker stated in a post that one could use a dictionary, but I can only find collections.

How To Prevent Duplicates In Listview
Hello to all,

Here is my lookup in a Listbox.
Search by LastName
CustID / LastName / FirstName / Contact / Phone
1 Don Joe Phillip 345-4335

Now, I populate my ListView when I click the Save button.

CustID / LastName / FirstName / Contact / Phone
1 Don Joe Phillip 345-4335
1 Don Joe Phillip 345-4335 (Invalid)

I don't want to enter a duplicate in the listview. How do you prevent this from happening.


Removing Duplicates From ListView
Dear all,

I found this code in PSC, and it seems great.

' By: Nate , Submitted on: 1/25/2005 2:38:39 AM
[b]' Remove Duplicates From Listview [/b]
Private Sub RemoveDuplicates(lst As ListView)
Dim lRet As ListItem
Dim strTemp As String
Dim intCnt As Integer
intCnt = 0

Do While intCnt <= lst.ListItems.Count - 1

intCnt = intCnt + 1
'Save the text that was in the listvew i
' ndex
strTemp = lst.ListItems.Item(intCnt).Text

lst.ListItems.Item(intCnt).Text = "" 'Remove the text inside the specific index
'Use the FindItem() call to search for t
' he specific item
Set lRet = lst.FindItem(strTemp, lvwText, lvwPartial)
'If the item is found, then it is a dupl
' icate and is removed

If Not lRet Is Nothing Then
lst.ListItems.Remove (lRet.Index)
End If
Loop While Not lRet Is Nothing 'If no item is found the loop is exited

lst.ListItems.Item(intCnt).Text = strTemp 'reset the listitem index text back To what it was, and Then continue
Debug.Print intCnt

DoEvents 'Added To ensure that the application does Not lock up when doing large amounts of data.

End Sub
The problrm is that it doesn't work for me.
When I run this line of code

Private Sub remove_dups_Click()
RemoveDuplicates (lstAlarms) ' That's is my ListView name
End Sub

An error is generated:
"RunTime error "438": Object doesn't support this proprty or method
Any help please!Edit by italkid: Yes there is a trick, use the [vb]][ and [/vb] tags to display your code, thanks.

Removing Duplicates From Listview
Hello, I'm after some advice.

Public Function RemoveDuplicates(List As ListView)

Dim lRet As ListItem, StrTemp As String, lngCnt As Long

lngCnt& = 0
List.Visible = False

Do While lngCnt& <= List.ListItems.Count - 1

lngCnt& = lngCnt& + 1
StrTemp$ = List.ListItems.Item(lngCnt&).Text


List.ListItems.Item(lngCnt&).Text = vbNullString$
Set lRet = List.FindItem(StrTemp, lvwText, lvwPartial)
If Not lRet Is Nothing Then
Call List.ListItems.Remove(lRet.Index)
lDuplicates& = lDuplicates& + 1
End If

Loop While Not lRet Is Nothing

List.ListItems.Item(lngCnt&).Text = StrTemp$
Debug.Print lngCnt&


List.Visible = True

End Function

I'm attempting to remove items from a listview however with my testing when the list has like 12k entries, it takes an incredibly long time, does anyone have any suggestions or possibly a faster method.

Before trying to add items, I attempted to use the .FindItem properly before adding but that method lags the program out.

Using a athlon 2200xp here.

Prevent Duplicates In Listview?
Ive been searchinf for like 30 minutes, and im wondering, how do you not allow dups into a listview? I only found removing after, and i want the api method that i saw quite a few months ago but cant seem to find (by martinliss?)

Checking For Duplicates In Listview
I would like to check if the value I'm about to enter into the listview already exists in my second column. How should I do that?

&lt;resolved&gt; Help, How To Find And Remove The File.
In order to get rid of some annoying spyware on my computer I am trying to edit the system.dat and user.dat files. But I can not do this becasue it does not allow me to save the changed.
The homepage of my browser is highjacked to one that is being loaded eveytime from (if you can do whatever you can to shutdown these bastards! and bless you for it.)
The spyware code must be java and contain the work somewhere but I can not find it on the machine.
SInce this forum is packed with programmers I thought someone might have a suggestion as how to deal with this problem.

How Do You Find A Char In A String And Remove It..
i have a string that has commas in it and i need to remove them.. i've searched the form but i dont see what i need... i'm guessing it would be somthing to do with the instr command?????

Find And Remove Item In Collection
This is a real newbie question but I rarely use collections

I have a collection where the item is a string. Do I have to loop through the collection to find and remove the item like I would if I was using an array? If the item was "abc123", would something like this work...
Private Sub RemoveHistoryItem()
    mcolHistory.Remove "abc123"
End Sub

God Bless America

How To Remove Or Find Out Blank Spaces (Urgent)
hello frds

I Use This Restriction On A Text Box.


VB Code:
If TxtAddress.Text = "" ThenMsgBox "Enter Address.....", vbCriticalTxtAddress.SetFocusexit Subend if
But It Does not Work When A User Enter Only Spaces With The Help Of Space Bar.
What should I Use Instead Of This Code So That I Can Restrict Any User To Enter Some Value In This Text Box.

ListView Remove
Ok.. I bet you guys here alot of this but my list view isnt removing when people leave the channel!

VB Code:
Public Sub Event_Leave(strUser, strFlag)On Error Resume NextfrmChat.lvChannel.ListItems.Remove (frmChat.lvChannel.FindItem(strUser).Index)AddSpeech vbGreen, "User " & strUser & " has left " & TheChannel & "."End Sub

Yes I made sure everything was named correctly..

Listview Remove
Hi All

I m Using
ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
to remove any item from listview it works fine but whan i use it to remove Multiple Selection It gives me error is there any other why to to this or please tell me what is wrong with this...

Sunil Sharma

Add/remove Programs Listview, How?
im trying to create the type of listview found in add/remove program in the control panel? dont know how and where to start

Listview Select Then Remove
Hello all i am trying to get a name from my listview and then delete it without the user selecting it from the listview itself.

Here is my code:

Private Sub NameBox_Click(Index As Integer)
strName = Replace(Left(NameBox(Index).Caption, InStr(NameBox(Index).Caption, vbCr)), vbCr, "")
NameBox(Index).Value = 1
LV1.SelectedItem = strName
x = LV1.SelectedItem.Index
LV1.ListItems.Remove x
End Sub
The strName is the name thats already populated in the listview. When the user clicks on a button it will find that name in the listbox and delete it.

But its not working.. Its just deleteing the first one from the listview. Can anyone help me out?


Remove ListView Item
Hi all,
I am trying to remove a ListView Item. My code doesn't seem to work, could someone please show me where my mistake is. Thanks a bunch.

Private Sub Command27_Click()

Dim a As Integer

a = GrowthList.SelectedItem.index

GrowthList.ListItems.Remove , , (a) 'This line gives the error

End Sub

Copyright 2005-08, All rights reserved