also check this:

http://www.excelforum.com/excel-programming-vba-macros/652705-import-specific-line-from-multiple-text-files.html

Cheers!!


On Thu, Jun 5, 2014 at 11:51 PM, Vaibhav Joshi <[email protected]> wrote:

> Hey
>
> use this for jumping to line..
>
> Sub GetMyData()
> Dim ff As Integer
>     ff = FreeFile
>
> Open "C:\Users\a\Desktop\new.txt" For Input As ff
>
>     mFile = Input(LOF(ff), #ff)
>
>     Close ff
>
>     Dim splitArr
>     splitArr = Split(mFile, vbCrLf)
>
>     Dim lineNum As Integer
>     lineNum = 1000   '<< change line number you want
>     MsgBox splitArr(lineNum - 1)
>
> End Sub
>
> Cheers!!
>
>
>
> On Thu, Jun 5, 2014 at 11:19 PM, Chris <[email protected]> wrote:
>
>> Hi there,
>>
>> I'm trying to read data from a text start and want to specify the start
>> row but can't figure this out. Is it possible to jump to a certain row in a
>> text file or do I have to go through them one by one until I hit the row I
>> want to read from?
>>
>> I was able to write code that's not very clean. Let's say my text file
>> has 1000 rows and I want to read data from row 50 to row 150. Then my code
>> looks like this:
>>
>> Sub GetMyData()
>> Open "C:\Users\example\Desktop\filename.txt" For Input As #1
>> i = 1
>> j = 1
>> Do Until ((EOF(1) = True) Or (j > 100))
>>
>>     If i < 50 Then     // Here I cycle through the first 49 rows and
>> basically do nothing
>>
>>         Input #1, tempstr
>>         i = i + 1
>>
>>     Else
>>
>>         Input #1, tempstr ' Get more data
>>
>>         Cells(j, 1) = Mid(tempstr, 7, 12)
>>         Cells(j, 2) = Mid(tempstr, 216, 3)
>>
>>         i = i + 1
>>         j = j + 1
>>
>>     End If
>>
>>
>> Loop
>> Close 1
>> End Sub
>>
>> The code works. However, in real life, I'm using this on a file that has
>> close to 5,000,000 rows and I need to start reading in the alst million
>> rows. So, to get there takes some time because it has to cycle through the
>> first 4,000,000 rows. Hence, I said that it's not clean code. Is there any
>> way where I can specify the starting row easily?
>>
>> Thanks so much for your help in advance.
>> Chris
>>
>> --
>> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
>> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
>> https://www.facebook.com/discussexcel
>>
>> FORUM RULES
>>
>> 1) Use concise, accurate thread titles. Poor thread titles, like Please
>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
>> will not get quick attention or may not be answered.
>> 2) Don't post a question in the thread of another member.
>> 3) Don't post questions regarding breaking or bypassing any security
>> measure.
>> 4) Acknowledge the responses you receive, good or bad.
>> 5) Jobs posting is not allowed.
>> 6) Sharing copyrighted material and their links is not allowed.
>>
>> NOTE : Don't ever post confidential data in a workbook. Forum owners and
>> members are not responsible for any loss.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "MS EXCEL AND VBA MACROS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/excel-macros.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to