D
David
XP/ XP Office
I have a list of words in a word doc file. One word on each line. I
have sorted the list. Many words are duplicated. I'm trying to
delete all duplicate words.
I've tried FIND(*^13)\1 REPLACE WITH \1, but it still leaves many
dups. It also takes over 4 minutes with 2700 words. I figured I
could iterate through the list once to remove dups.
So I wrote this code...
'Remove any dup lines
Dim Word1, Word2 As Range
Set Word1 = Documents("WorkArea1.doc").Words(1)
NumOfWords% = Documents("WorkArea1.doc").Words.Count
For A% = 2 To NumOfWords
Set Word2 = Documents("WorkArea1.doc").Words(A)
If Word1 = Word2 Then '<<<< Problem here
Documents("WorkArea1.doc").Words(A).Delete
Else
Word1 = Documents("WorkArea1.doc").Words(A)
End If
Next
But then it compares Word1 to Word2, either one or the other always is
empty. When I step through, and it steps past Set Word2, I hover the
cursor over each range, and they both contain words, but as soon as I
compare, one is always empty.
What am I doing wrong?
I have a list of words in a word doc file. One word on each line. I
have sorted the list. Many words are duplicated. I'm trying to
delete all duplicate words.
I've tried FIND(*^13)\1 REPLACE WITH \1, but it still leaves many
dups. It also takes over 4 minutes with 2700 words. I figured I
could iterate through the list once to remove dups.
So I wrote this code...
'Remove any dup lines
Dim Word1, Word2 As Range
Set Word1 = Documents("WorkArea1.doc").Words(1)
NumOfWords% = Documents("WorkArea1.doc").Words.Count
For A% = 2 To NumOfWords
Set Word2 = Documents("WorkArea1.doc").Words(A)
If Word1 = Word2 Then '<<<< Problem here
Documents("WorkArea1.doc").Words(A).Delete
Else
Word1 = Documents("WorkArea1.doc").Words(A)
End If
Next
But then it compares Word1 to Word2, either one or the other always is
empty. When I step through, and it steps past Set Word2, I hover the
cursor over each range, and they both contain words, but as soon as I
compare, one is always empty.
What am I doing wrong?