ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading a *.csv file from different points (https://www.excelbanter.com/excel-programming/358092-reading-%2A-csv-file-different-points.html)

WannaBeExceller

Reading a *.csv file from different points
 
I have a *.csv file that I would like to read depending on a list of lines
that I have. I was wondering how I can do that. Eg. I want to read line 300,
202, .... can I just jump to the line I want and read it? How can I
accomplish this if I cannot read it from any line?

AMDRIT

Reading a *.csv file from different points
 
On variable length lines, you cannot just "skip around" as you are asking.
However, you could make a routin to simulate this by making small use of the
SEEK command to reset the position back to the top of the file.

private function readaline(hFilePtr as long, intRowNumber as long) as string
dim vLine as variant, iLoop as long

'Move to beginning of file (vastmseek.htm)
Seek hFileptr, 1

iloop=0

do while not eof(hFilePtr)
iloop = iloop + 1
line input #hfielptr, vLine
if iLoop =IntRowNumber
exit do
else
vline="" 'Clear any bad data
end if
loop

readaline=cstr(vLine)

end function


HTH

"WannaBeExceller" wrote in
message ...
I have a *.csv file that I would like to read depending on a list of lines
that I have. I was wondering how I can do that. Eg. I want to read line
300,
202, .... can I just jump to the line I want and read it? How can I
accomplish this if I cannot read it from any line?




WannaBeExceller

Reading a *.csv file from different points
 
Thank you very much AMDRIT. It worked like magic! Thank you.



All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com