VB-AN-IZ
11-01-2015, 02:43 PM
Assembling wordlists from various sources invariably results in identical paragraphs. I've found a macro that deletes all of the repeated paragraphs, listing one version of each repeated paragraph, but now I need one that deletes the repeated paragraphs as well as the original. So the existing one will turn this:
A
A
A
B
C
C
D
E
E
E
..into:
A
B
C
D
E
But I need one that will only keep the paragraphs that aren't repeated:
B
D
How would I modify the existing macro so it removes all paragraphs that are duplicated?
Thanks!
Dim AmountMoved As Long
Dim myRange As Range
Set myRange = ActiveDocument.Paragraphs(1).Range
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
Do While AmountMoved > 0
If myRange.Paragraphs(1).Range.Text = _
myRange.Paragraphs(2).Range.Text Then
myRange.Paragraphs(2).Range.Delete
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
Else
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
myRange.MoveStart Unit:=wdParagraph, Count:=1
End If
Loop
End Sub
A
A
A
B
C
C
D
E
E
E
..into:
A
B
C
D
E
But I need one that will only keep the paragraphs that aren't repeated:
B
D
How would I modify the existing macro so it removes all paragraphs that are duplicated?
Thanks!
Dim AmountMoved As Long
Dim myRange As Range
Set myRange = ActiveDocument.Paragraphs(1).Range
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
Do While AmountMoved > 0
If myRange.Paragraphs(1).Range.Text = _
myRange.Paragraphs(2).Range.Text Then
myRange.Paragraphs(2).Range.Delete
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
Else
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
myRange.MoveStart Unit:=wdParagraph, Count:=1
End If
Loop
End Sub