PDA

View Full Version : Solved: read text file question



vzachin
09-24-2011, 06:07 PM
hi,

i know how to read a text file but it always starts on row 1. is there a way to read the file beginning on a certain row, say 5?


thanks
zach

GTO
09-24-2011, 06:35 PM
From vba help (excel 2000) for SkipLine Method:

Description
Skips the next line when reading a TextStream file.
Syntax
object.SkipLine
The object is always the name of a TextStream object.
Remarks
Skipping a line means reading and discarding all characters in a line up to and including the next newline character.
An error occurs if the file is not open for reading.

Paul_Hossler
09-24-2011, 06:50 PM
AFAIK, if it's a text file of variable length records each ending in a CR/LF, the computer has to read through it anyways, so it might be easier to just read and ignore the first 4 lines

Paul

shrivallabha
09-25-2011, 05:25 AM
What Paul said. Dim one counter variable like:

Dim RowCounter as Long
Open MyTxtFile For Input As #1
RowCounter = 1
Do While Not EOF(1)
Line Input #1, Data
Select Case RowCounter
Case 1, 2, 3, 4
'Do nothing
Case Else
'Line Reading code here!
End Select
RowCounter = RowCounter + 1
Loop
Close #1

vzachin
09-26-2011, 04:12 AM
thanks mark,paul & shrivallabha


zach