The problem is that text files cannot be analysed by a worksheet type way for like last row
Lr= ….. .End(Xlup).row ….… and so on. That does not work in a text file. We do not have rows in a text file
In a text file, we talk about instead lines and records
Excel file row is only approximately = Text file line or Text file record
In text file for last record, or last line, we use
EOF ( https://docs.microsoft.com/en-us/off...p/eof-function )
Or
we do it another way. Your file in post#1 was like
NSE, ,
NSE, ,
NSE, ,
, ,
, ,
, , Explanation etc .
So I did do check for “NSE,” for last data that you wanted
So for no extra lines like below, like in sample2BEFORE.csv , it does not work too well
NSE, ,
NSE, ,
NSE, ,
( See here for more info, just for info, not important :
Original text files : https://excelfox.com/forum/showthrea...ge32#post13475
https://excelfox.com/forum/showthrea...ge32#post13476
Text files post#29 : https://excelfox.com/forum/showthrea...ll=1#post13618 )
So solution to this problem
Change .._
-..To thisCode:Do While Left(TextFileLineIn, 4) = "NSE," ' For text file lines like NSE,101010,6,<,12783,A,,,,,GTT that may have extra unwanted lines like in one Avinash uses stupidly for explanations Let RwCnt = RwCnt + 1 Line Input #FileNum, TextFileLineIn ' next line in text file Loop
Full macro here:Code:Do While Not EOF(FileNum) = True And Left(TextFileLineIn, 4) = "NSE," ' Left(TextFileLineIn, 4) = "NSE," ' For text file lines like NSE,101010,6,<,12783,A,,,,,GTT that may have extra unwanted lines like in one Avinash uses stupidly for explanations Let RwCnt = RwCnt + 1 ' for first and subsequent lines given by below. ... but Line Input #FileNum, TextFileLineIn ' next line in text file Loop If EOF(FileNum) = True Then Let RwCnt = RwCnt + 1 ' ... but if the last line I want is EOF, I will not catch it in the loop so must add a 1 here
https://excelfox.com/forum/showthrea...ll=1#post13619
Share ‘sample2BEFORE.csv’ : https://app.box.com/s/d8lu7iatfv6h8spp9eru8asm3h4v4e4p
Share ‘Sample2After.csv’ : https://app.box.com/s/0j4118cwzzofe76ytb5rqkvz3qj0vseu
vba.xlsm : https://app.box.com/s/juekenyll42z84j6ms7qonzsngnugoyo
Sample1.xls : https://app.box.com/s/xh58fgjl74w06hvsd53jriqkohdm6a3q
macro.xlsm : https://app.box.com/s/z358r7tbc9hzthi539dlj49jsf4gyg8p
1.xls : https://app.box.com/s/38aoip5xi7018y9syt0xe4g04u95l6xk




Reply With Quote

Bookmarks