Thread: read text file
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Flanagan Bob Flanagan is offline
external usenet poster
 
Posts: 340
Default 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