how do you skip lines when reading a text file

Y

Yaw Bonsu

Open Strfilename For Input As #iFile
i = 1
Do While Not EOF(iFile)
e = Input(1, #iFile)
z = ""
Do While Not (e = Chr(13) or e = Chr(13)+Chr(10))
z = z & e
e = Input(1, #iFile)
Loop
'Input #iFile, z 'original code begins on this
line
Range("Sheet1!a" & i).Value = z
*** Go to the next line in input...(how do I code that?)
'Input #iFile, z
'Range("Sheet1!b" & i).Value = z
'i = i + 1 'original code ends on this line
Loop
Close #iFile
Exit Sub

Using the code above, I'm trying to skip to the next line in the input
file, the code abov runs a never-ending loop and reads the same line
over and over again. Please help.
 
T

Tom Ogilvy

Sub ReadFile()
Dim strFileName As String
Dim i As Long
Dim sLine As String
Dim ifile As Long
strFileName = "C:\data\eclipse.txt"
ifile = FreeFile()
Open strFileName For Input As #ifile
i = 1
Do While Not EOF(ifile)
Line Input #ifile, sLine
Debug.Print i, sLine
i = i + 1
Loop
Close (ifile)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top