ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Convert textfiles into excel (https://www.excelbanter.com/excel-worksheet-functions/121966-convert-textfiles-into-excel.html)

Maniv

Convert textfiles into excel
 
Hi

I have text files with more than 65536 lines which I want to convert to
excel (I don't want to get into ACCESS, Foxpro,etc). It must copy, say, 60000
into sheet1; copy 60001-120000 into sheet2, and so on till the entire text
file is converted.

Regards
Mani


Bernie Deitrick

Convert textfiles into excel
 
Mani,

Below is the standard large file import macro...

HTH,
Bernie
MS Excel MVP

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 = Application.GetOpenFilename
'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
If ActiveCell.Row = 60000 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



"Maniv" wrote in message
...
Hi

I have text files with more than 65536 lines which I want to convert to
excel (I don't want to get into ACCESS, Foxpro,etc). It must copy, say, 60000
into sheet1; copy 60001-120000 into sheet2, and so on till the entire text
file is converted.

Regards
Mani




Maniv

Convert textfiles into excel
 

Hi Bernie

Thanks a ton.. I have been going through the various replies / code that you
post at this portal.. Pl keep up the good work..

Warm regards
Mani


"Bernie Deitrick" wrote:

Mani,

Below is the standard large file import macro...

HTH,
Bernie
MS Excel MVP

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 = Application.GetOpenFilename
'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
If ActiveCell.Row = 60000 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



"Maniv" wrote in message
...
Hi

I have text files with more than 65536 lines which I want to convert to
excel (I don't want to get into ACCESS, Foxpro,etc). It must copy, say, 60000
into sheet1; copy 60001-120000 into sheet2, and so on till the entire text
file is converted.

Regards
Mani





Bernie Deitrick

Convert textfiles into excel
 
Kind of you to say, but, well, this code certainly isn't mine. It was
copied off the MS web site about the turn of the century ;-)

Bernie
MS Excel MVP


"Maniv" wrote in message
...

Hi Bernie

Thanks a ton.. I have been going through the various replies / code that
you
post at this portal.. Pl keep up the good work..

Warm regards
Mani




Kathy

Convert textfiles into excel
 
I used the above script to import a text file with about 150k lines. All the
data was imported, but it never asked me how I wanted the columns formatted
so everything was lumped into a single cell per row. Is there a way to have
the wizard pop up and allow the user to determine where the column breaks
should be and perhaps allow the user to select which row to start the import?

The users will need to import various text files with different columns of
data so I can not easily create a macro that will automatically separate the
data into columns. The ability to use the wizard would be ideal.

We are running Excel 2003 SP2. Any help would be appreciated.


"Bernie Deitrick" wrote:

Kind of you to say, but, well, this code certainly isn't mine. It was
copied off the MS web site about the turn of the century ;-)

Bernie
MS Excel MVP


"Maniv" wrote in message
...

Hi Bernie

Thanks a ton.. I have been going through the various replies / code that
you
post at this portal.. Pl keep up the good work..

Warm regards
Mani






All times are GMT +1. The time now is 06:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com