Importing text files by specific line number

kevbo5566

New Member
Joined
Jun 7, 2011
Messages
1
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,505
Messages
6,179,147
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top