Results 1 to 11 of 11
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete Duplicate Lines (97 SR2)

    I'm sure it'll have to be a macro, but i'm not quite sure where to start..

    I'd like to delete duplicate lines... any ideas?
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    If the lines end in paragraph marks, this wildcard Find/Replace does the trick:

    Find what: ^13(*^13)1
    Replace with: ^p1
    and repeat the search until nothing more is found.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Regards, Klaus

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Does this require me to pre-select a string?

    The lines are duplicate, but they repeat. This is in regards to several duplicate e-mail addresses I have in list format.

    This makes it impossible for me to preselect what lines need to be replaced, and I can't seem to get this 'trick' to work..

    Perhaps you can give me some more guidance? <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Thanks!
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Hi Drk:

    The format Klaus used will work for any repeating pattern that exists between paragraph marks. It works best if you insert a paragraph mark at the top (otherwise it will leave 2 duplicates, which are easy enough to delete manually).

    However, if your repeating paragraph(s) are separated by varying non-repeating paragraphs, it won't eliminate duplicates.

    e.g. if you have the following names
    Phil Rabichow
    DrkRealm
    Klaus Linke
    Phil Rabichow
    Bob Smith
    Phil Rabichow
    Tom Jones

    it will not eliminate the name "Phil Rabichow"

    I hope this is clear enough.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    If your text looks like Phil's sample, you could sort the paragraphs first ("Table > Sort..." works fine with paragraphs, too -- you don't have to convert them to a table).

    Should this not be an option, you can use the following macro. It formats double paragraphs as "hidden"; you can later check if the right paragraphs are marked hidden and delete them with a Find/Replace.
    To speed up the macro, I did all string comparisons directly in memory.
    The macro has some limitations (it won't work if you have tables in your document, and it won't find paragraphs that differ in non-printing characters like page breaks or non-breaking spaces).

    <pre>Sub DelDoubleParas()
    Dim myArray, i, j
    myArray = Split(ActiveDocument.Content.text, Chr(13))

    For i = 0 To UBound(myArray) - 2
    For j = i + 1 To UBound(myArray) - 1
    If myArray(j) = myArray(i) Then
    ActiveDocument.Paragraphs(j + 1).Range.Font.Hidden = True
    End If
    Next j
    Next i
    End Sub</pre>


    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Greetings, Klaus

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Hi Klaus:

    This is great. How would you modify the macro to change the formatting for only selected text?

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Hi Phil,

    It's only a small change (but I added some code to make it safer to use):
    <pre>Sub HideDoubleParasInSel()
    Dim myArray, i, j
    Dim Remember As Boolean
    Remember = ActiveWindow.View.ShowHiddenText
    ActiveWindow.View.ShowHiddenText = True

    myArray = Split(Selection.text, Chr(13))

    For i = 0 To UBound(myArray) - 2
    For j = i + 1 To UBound(myArray) - 1
    If myArray(j) = myArray(i) Then
    Selection.Paragraphs(j + 1).Range.Font.Hidden = True
    End If
    Next j
    Next i
    ActiveWindow.View.ShowHiddenText = Remember

    End Sub</pre>

    This will format paragraphs that occur more than once in the current selection as "hidden".
    You could use
    <pre>If CleanString(myArray(j)) = CleanString(myArray(i)) Then</pre>

    to make the comparison independent of special characters like non-breaking spaces.


    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Greetings, Klaus

  8. #8
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Klaus,

    I've used Find/Replace alot with Wildcards but don't understand your syntax:

    Find what: ^13(*^13)1
    Replace with: ^p1

    What does the 1 on the FW line do (I know what it does on the RW line)? I checked Word and is not listed in the FW items, so I'd presume it's treated as a "normal" character.

    Fred

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Hi Fred:

    I'm not Klaus (as you know), but the 1 does the same thing in the Find box as the replace box. i.e. it finds whatever was in the parenthesis. So
    Find: ^13(*^13)1 finds a paragraph mark, followed by anything until the next paragraph mark is reached, & then 1 finds a duplicate. If you don't use the 1 in find, you don't eliminate anything. You have to find the same thing twice & replace it with one "find" only, then repeat. It's really ingenious & hadn't used it before Klaus mentioned it.

    Hope this helps.

  10. #10
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Hi Phil,

    Thks for the response.

    When I read Klaus's post, I thought I understood what 1 was doing in the Find What box. I just wasn't sure whether that was valid syntax in the FW box. I thought, from my post, that would NOT be interpreted as a special character in FW since it wasn't listed in the list under Special. Thanks for confirming that it does work there as well.

    Now the question is, how would one have known that? But Klaus's approach is really clever to make use of it.

    Funny thing: on the TV in the background, Regis is talking about the launch of Windows XP yesterday with Bill Gates. He said he tried to play Who wants to be a millionaire with Bill.

    Fred

  11. #11
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Duplicate Lines (97 SR2)

    Thank you Phil for jumping in. I don't check in at Woody's Lounge that regularly.

    Another application for 1 in search strings might be finding properly nested XML tags:
    Find what: <(*>)*</1

    This will match any well-formed XML element like something italic or <CustomerName>Klaus Linke</CustomerName>.
    This is a bit hard to read, because all pointed brackets < and > have to be escaped with a backslash.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Greetings, Klaus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •