remove duplicate lines in text file

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
9,592
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.
 

yinkajewole

Active Member
Joined
Nov 23, 2018
Messages
267
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.
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
9,592
Change this line:

Code:
Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] , Mid(MyResult, 2)
to

Code:
Print [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] , Mid(MyResult, 2, Len(MyResult) - 2)
</pre>
 

yinkajewole

Active Member
Joined
Nov 23, 2018
Messages
267
it errors: "Bad file name or number"
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
9,592
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 [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL]  , MyResult
I assume you're not using the "|" symbol anywhere in your file. If so, we can find something else.
 

Watch MrExcel Video

Forum statistics

Threads
1,096,248
Messages
5,449,242
Members
405,560
Latest member
Jadax

This Week's Hot Topics

Top