I am having problems importing specific lines of a text file into an excel document. I have an excel document with a range of numbers (approximately 30) which correspond to line numbers in a text file. I'd like to be able to import the entire line number, but only those which correspond to the numbers in the range. My text file is also very large, on the order of 1.6 million lines (possibly the source of my issues).
I have created a function (see below) which does this, but only works for smaller text files (200 K or so). I end up getting a #VALUE! error in the excel cell when it doesn't work. Could someone take a look at my code and offer some guidance on why this may be happening and what I can do to fix it?
Thanks for your help.
-----code-----
'myline is an integer in the range of cells
Function IMPORTVAL(ByVal myline As Integer) As Variant
Dim fn As String
Dim txt As Variant
'text file
fn = "D:\Documents and Settings\kevin.byers\Desktop\curve00001.txt"
txt = Space(FileLen(fn))
Open fn For Input As #1
Get #1, , txt
Close #1
IMPORTVAL = Split(txt, vbCrLf)(myline - 1)
End Function
I have created a function (see below) which does this, but only works for smaller text files (200 K or so). I end up getting a #VALUE! error in the excel cell when it doesn't work. Could someone take a look at my code and offer some guidance on why this may be happening and what I can do to fix it?
Thanks for your help.
-----code-----
'myline is an integer in the range of cells
Function IMPORTVAL(ByVal myline As Integer) As Variant
Dim fn As String
Dim txt As Variant
'text file
fn = "D:\Documents and Settings\kevin.byers\Desktop\curve00001.txt"
txt = Space(FileLen(fn))
Open fn For Input As #1
Get #1, , txt
Close #1
IMPORTVAL = Split(txt, vbCrLf)(myline - 1)
End Function