ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Read text data (https://www.excelbanter.com/excel-programming/307171-read-text-data.html)

hallie

Read text data
 
I've come up with the code but I don't know why there is
any error message highlighted at


Do While Not EOF(1)
Line Input #1, data
Worksheets("Sheet1").Activate
Line: Cells(i, 1).Value = Mid(data, 1, 8)
i=i +1
Loop



Tom Ogilvy

Read text data
 
Per you later post, I believe you haven't initialized the value of i prior
to entering the loop. Thus in the cells(i,1) line it would resolve to
cells(0,1) which will give you an error.

--
Regards,
Tom Ogilvy

"hallie" wrote in message
...
I've come up with the code but I don't know why there is
any error message highlighted at


Do While Not EOF(1)
Line Input #1, data
Worksheets("Sheet1").Activate
Line: Cells(i, 1).Value = Mid(data, 1, 8)
i=i +1
Loop





Jim Rech

Read text data
 
If i = 0 initially that will error. If so, put i = i + 1 before the Cells
line.

Is there any reason to Activate Sheet1 in the loop? If not, put the
activate before the loop. In fact, if you use:

Worksheets("Sheet1").Cells(i, 1).Value = Mid(data, 1, 8)

you do not an activate at all.

--
Jim Rech
Excel MVP
"hallie" wrote in message
...
| I've come up with the code but I don't know why there is
| any error message highlighted at
|
|
| Do While Not EOF(1)
| Line Input #1, data
| Worksheets("Sheet1").Activate
| Line: Cells(i, 1).Value = Mid(data, 1, 8)
| i=i +1
| Loop
|
|



hallie

Read text data
 
Hi Tom & Jim ,

In fact I've initialized to i to 1 before the start of
loop

I've replaced my code with the line below...

Worksheets("Whinv").Cells(i, 1).Value = Mid(data, 1, )

When I run , error stops at above line with same error
code of 1004 Application defined or object defined
error...

But my excel column is populated with values with blanks
rows in between certain rows eg..

A column
Row1 data1
Row2
Row3
Row3 data2
Row4
Row5 data3 etc etc




hallie

Read text data
 
Thanks to everyone for your suggrstion..

I've found out the cause .. It's my silly mistake.
my counter increment was wrong. I treat "i" as 1.I'm not
going to use i as a variable again...



All times are GMT +1. The time now is 02:24 PM.

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