finding repeats in a word list

  • Thread starter Thread starter inlightu2
  • Start date Start date
I

inlightu2

I have a long list of diff suppiles but there is repeats and how can I find
them and remove them?
 
I just recorded the basics, removed a lot of the excess, and added the
deduplication loop, and this is what I got. It is not pretty code but I
think it will do what you want if your document is simply a list and nothing
else; it may need some tweaking if you have, say, redundant spaces. Anyway,
here it is: please try it on a *copy* of your document.

Sub Macro1()
Selection.WholeStory
WordBasic.TextToTable
Selection.InsertColumns
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:=
_
ListGalleries(wdNumberGallery).ListTemplates(1)
ActiveDocument.ConvertNumbersToText
With ActiveDocument.Tables(1)
.Sort ExcludeHeader:=False, FieldNumber:="Column 2", _
SortFieldType:=wdSortFieldAlphanumeric
For Each ro In .Rows
Do
If ro.Index = ro.Parent.Rows.Last.Index Then Exit For
If ro.Cells(2).Range = ro.Next.Cells(2).Range Then
ro.Next.Delete
Else
Exit Do
End If
Loop
Next
.Sort ExcludeHeader:=False, FieldNumber:="Column 1", _
SortFieldType:=wdSortFieldAlphanumeric
.Columns(1).Delete
.Rows.ConvertToText Separator:=wdSeparateByParagraphs
End With
End Sub

If you don't know what to do with this, see
http://www.gmayor.com/installing_macro.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top