Consulting

Results 1 to 5 of 5

Thread: Solved: read text file question

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    Solved: read text file question

    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

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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

  4. #4
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    What Paul said. Dim one counter variable like:
    [VBA]
    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
    [/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  5. #5
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    thanks mark,paul & shrivallabha


    zach

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •