IMPORT LARGE TEXT FILE INTO MULTIPLE WORKSHEETS

dgr

Board Regular
Joined
Apr 24, 2005
Messages
176
Dear All,
I trust that this message finds you all in good health & wealth. I need your help on this matter:-

I have a large tab delimited text file with more than 75,000 records. I'd like to import it into multiple worksheets with each sheet containing not more than 30,000 records. I will manually create additional worksheets before starting the import job so you don't have to worry about that.

Excel's Import Wizard says it can be done but there does not seem to be a proper way to do it.

I'm looking for a VB macro to do this.

Thank you for your guidance.

ROBERT RAM
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You will first have to split the text file into 2 pieces, neither of which can be more than 65536 lines.
 
Upvote 0
Or use Access until the next version of Excel. (LOTS of rows!) Or, skip a column after the last column in your data, and continue with Row 1. (Edit: Skip a column, not split the text file.)
 
Upvote 0
Thank you for your replies Ken & Taz.

I do not want to use Access or split the text file which is why I posted my question here.

Warm Regards.

ROBERT RAM
 
Upvote 0
Thanks a lot DK. I've tried that. It gave an error message half way thorugh & stopped working. I got the following code from another website which is working fine :-

Sub LargeFileImport()

'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
'Ask User for File's Name
FileName = InputBox("Please enter the Text File's name, e.g. test.txt")
'Check for no entry
If FileName = "" Then End
'Get Next Available File Handle Number
FileNum = FreeFile()
'Open Text File For Input
Open FileName For Input As #FileNum
'Turn Screen Updating Off
Application.ScreenUpdating = False
'Create A New WorkBook With One Worksheet In It
Workbooks.Add template:=xlWorksheet
'Set The Counter to 1
Counter = 1
'Loop Until the End Of File Is Reached
Do While Seek(FileNum) <= LOF(FileNum)
'Display Importing Row Number On Status Bar
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & FileName
'Store One Line Of Text From File To Variable
Line Input #FileNum, ResultStr
'Store Variable Data Into Active Cell
If Left(ResultStr, 1) = "=" Then
ActiveCell.Value = "'" & ResultStr
Else
ActiveCell.Value = ResultStr
End If

'For Excel versions before Excel 97, change 65536 to 16384
If ActiveCell.Row = 65536 Then
'If On The Last Row Then Add A New Sheet
ActiveWorkbook.Sheets.Add
Else
'If Not The Last Row Then Go One Cell Down
ActiveCell.Offset(1, 0).Select
End If
'Increment the Counter By 1
Counter = Counter + 1
'Start Again At Top Of 'Do While' Statement
Loop
'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub

I appreciate your initiative & help on this matter. Thank you once again.

Warm Regards
ROBERT RAM
 
Upvote 0
Hi,

Am I correct in saying that you're using Excel 97? I should have mentioned that the code I referred to will only work on Excel 2000 or above.

Regards
Daniel
 
Upvote 0
No, I'm using excel xp. However, for some strange reason, the code on danielklann's website did not work. It kept giving me error messages.

I appreciate your good intentions. It's not your fault.

Warm Regards

ROBERT RAM
 
Upvote 0

Forum statistics

Threads
1,216,025
Messages
6,128,358
Members
449,444
Latest member
abitrandom82

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