ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   read text file (https://www.excelbanter.com/excel-programming/307175-read-text-file.html)

hallie

read text file
 
my text file is of fixed width format..I have 2 problems
that I've tried to troubleshoot..

1) An error is highlighted at Line 5 (RunTime error 1004
Application-defined or object-defined error)

2)The data was correctly diplayed in cells BUT there are
blanks rows between the cells with correct data( the nos
of blank row varies)


par of the code:
Do While Not EOF(1)
Line Input #1, data
Worksheets("Sheet1").Activate

Line5: Cells(i, 1).Value = Mid(data, 1, 8)
i=i+1
Loop


some kind member pls advise ...thanks


Bob Flanagan

read text file
 
Hallie, what is the initial value if "i"? Is it zero? If so, that would
mean that your macro is trying to write to cells(0,1), which does not exist.
Is the error occuring after some lines have been read in? If so, then
Mid(data, 1,8) is returning something that Excel is tryng to calculate or
put into a cell that won't fit. if so, then when the error happs highlight
Mid(data, 1, 8) and do a watch on it to see what the characters are. If all
the data you are reading in is text, then you could do this:

Cells(i, 1).Value = "'" & Mid(data, 1, 8)

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"hallie" wrote in message
...
my text file is of fixed width format..I have 2 problems
that I've tried to troubleshoot..

1) An error is highlighted at Line 5 (RunTime error 1004
Application-defined or object-defined error)

2)The data was correctly diplayed in cells BUT there are
blanks rows between the cells with correct data( the nos
of blank row varies)


par of the code:
Do While Not EOF(1)
Line Input #1, data
Worksheets("Sheet1").Activate

Line5: Cells(i, 1).Value = Mid(data, 1, 8)
i=i+1
Loop


some kind member pls advise ...thanks




hallie

read text file
 
Hi Bob,
thanks for your reply...
I declare i as long and set it to 1 before the start of
the DO while loop..
Yes correct data is wriiten to the cells but there are
blanks rows between those rows with data in it...it's
strange

I tried Cells(i, 1).Value = "'" & Mid(data, 1, 8) ...
same results..





All times are GMT +1. The time now is 06:33 PM.

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