-1

I am learning to use VBA scripts for Excel macros. I have trouble to find the best examples of scripts to read the specific lines from text file and fill excel cells. For example, a text file has 100 lines. I would like to read lines 67 to 76 and fill Excel cells. I could not use .readall or .readline ??

Please help me out :)

now, will that script able to read lines 67 to 76 per text files. I have around 100 text files with same format.. can it print lines per file per cell on excel ?

Community
  • 1
  • 1
Teena
  • 1
  • 2
  • [Check this out](http://stackoverflow.com/questions/20888220/is-there-a-way-to-navigate-backwards-in-a-textstream-file) – Pankaj Jaju Jan 10 '14 at 16:30

1 Answers1

1

Perhaps something like:

Sub ImportFile()
    Dim J As Long, K As Long
    Close #1
    Open "C:\TestFolder\TestFile.txt" For Input As #1
    J = 1
    K = 0
    Do While Not EOF(1)
        K = K + 1
        Line Input #1, TextLine
        If K > 66 And K < 77 Then
            Cells(J, 1) = TextLine
            J = J + 1
        End If
    Loop
    Close #1
End Sub
Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • Ahh well .. the question is changed. No worries now :) – Pankaj Jaju Jan 10 '14 at 16:48
  • yes, I just wanted to know the two options. 1. for single text file to read. 2. for multiple text files to read. Both options receive the same results is to fill excel cells when it reads the lines between 67 to 76 lines. – Teena Jan 10 '14 at 20:31