Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: remove duplicate lines in text file
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular
    Join Date
    Nov 2018
    Posts
    209
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: remove duplicate lines in text file

    Quote Originally Posted by Eric W View Post
    Glad to help.
    I'm sorry, i just realised that the code you gave me always add some empty lines at the bottom, can this be rectified?
    Last edited by yinkajewole; May 22nd, 2019 at 04:50 AM.

  2. #12
    MrExcel MVP Eric W's Avatar
    Join Date
    Aug 2015
    Location
    Bountiful, UT
    Posts
    8,718
    Post Thanks / Like
    Mentioned
    45 Post(s)
    Tagged
    5 Thread(s)

    Default Re: remove duplicate lines in text file

    Not sure why that would be, unless you have some empty lines at the end of your input file. You can try changing this line:

    Code:
    If InStr(1, MyResult, vbCrLf & MyLines(i) & vbCrLf, vbTextCompare) = 0 Then
    to
    Code:
    If InStr(1, MyResult, vbCrLf & MyLines(i) & vbCrLf, vbTextCompare) = 0 And MyLines(i) <> "" Then
    If that doesn't work, let me know.
    Cheers,
    Eric

    When you eliminate the impossible, whatever remains, however improbable, must be the truth.

    -Posting guidelines, forum rules, terms of use, FAQs, BB codes, See how to search the forum
    -Post a screen shot with the HTML Maker

  3. #13
    Board Regular
    Join Date
    Nov 2018
    Posts
    209
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: remove duplicate lines in text file

    If that doesn't work, let me know.[/QUOTE]
    it worked partially.
    Actually, the empty line used to be three lines there. The code I used to write the text file do add an empty line, while yours do add two, making three altogether.
    So this code you gave me
    Code:
    If InStr(1, MyResult, vbCrLf & MyLines(i) & vbCrLf, vbTextCompare) = 0 And MyLines(i) <> "" Then
    reduced the lines to two altogether.

  4. #14
    MrExcel MVP Eric W's Avatar
    Join Date
    Aug 2015
    Location
    Bountiful, UT
    Posts
    8,718
    Post Thanks / Like
    Mentioned
    45 Post(s)
    Tagged
    5 Thread(s)

    Default Re: remove duplicate lines in text file

    Change this line:

    Code:
    Print #1 , Mid(MyResult, 2)
    to

    Code:
    Print #1 , Mid(MyResult, 2, Len(MyResult) - 2)
    Cheers,
    Eric

    When you eliminate the impossible, whatever remains, however improbable, must be the truth.

    -Posting guidelines, forum rules, terms of use, FAQs, BB codes, See how to search the forum
    -Post a screen shot with the HTML Maker

  5. #15
    Board Regular
    Join Date
    Nov 2018
    Posts
    209
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: remove duplicate lines in text file

    it errors: "Bad file name or number"

  6. #16
    Board Regular
    Join Date
    Nov 2018
    Posts
    209
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: remove duplicate lines in text file

    Sorry, It still had two lines

  7. #17
    MrExcel MVP Eric W's Avatar
    Join Date
    Aug 2015
    Location
    Bountiful, UT
    Posts
    8,718
    Post Thanks / Like
    Mentioned
    45 Post(s)
    Tagged
    5 Thread(s)

    Default Re: remove duplicate lines in text file

    It's a bit tough to debug at a distance without seeing the file, but here's one last idea. Add one line before the Print #1 line, and change that line to:


    Code:
    MyResult = Replace(Replace(Trim(Replace(Replace(MyResult, " ", "|"), vbCrLf, " ")), " ", vbCrLf), "|", " ")
    Print #1  , MyResult
    I assume you're not using the "|" symbol anywhere in your file. If so, we can find something else.
    Cheers,
    Eric

    When you eliminate the impossible, whatever remains, however improbable, must be the truth.

    -Posting guidelines, forum rules, terms of use, FAQs, BB codes, See how to search the forum
    -Post a screen shot with the HTML Maker

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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