Quick Question ?

  • Thread starter Thread starter susan_voyce
  • Start date Start date
S

susan_voyce

Hi,

Could anybody tell me , how to import one particular column in tex
file of 80MB, to Excel sheet.

Thanks
 
Susan,

Open the file for read only, read in each line, parse out the text to an
array using split, read the element that you need, and write it into your
Excel file.

I just posted a routine to do something very similar, except it wrote to a
file rather than to Excel. Here's the code, below, which I modified slightly
but which you will need to finish, since you don't give many details. Copy
the code into a module in an otherwise empty workbook. The values will be
written into the activesheet.

HTH,
Bernie
MS Excel MVP

Option Explicit
Sub GetOneColumns()
Dim ResultStr As String
Dim FileName As String
Dim FileNumIn As Integer
Dim ResultsArray As Variant
Dim Counter As Double
Dim myCell As Range

Counter = 0

FileName = Application.GetOpenFilename
If FileName = "" Then End

FileNumIn = FreeFile()
Open FileName For Input As #FileNumIn

Set myCell = Range("A65536")

Do While Seek(FileNumIn) <= LOF(FileNumIn)
Counter = Counter + 1
Application.StatusBar = "Processing line " & Counter
Line Input #FileNumIn, ResultStr
ResultsArray = Split(ResultStr, vbTab)
'ResultsArray is a 0 based array of the tab-delimited values
'This example writes the second column of data into Excel
'starting in column A and moving across the worksheet
'It will write 65,500 values into each column
myCell.End(xlUp)(2).Value = ResultsArray(1)
If myCell.End(xlUp)(2).Row = 65501 Then
Set myCell = myCell(1,2)
End If
Print #FileNumOut, WholeLine
Loop

Close FileNumIn
Close #FileNumOut

Application.StatusBar = False

End Sub
 
Ooops, forgot to remove the line

Close #FileNumOut

from the bottom of the routine.

Sorry about that,
Bernie
MS Excel MVP

Bernie Deitrick said:
Susan,

Open the file for read only, read in each line, parse out the text to an
array using split, read the element that you need, and write it into your
Excel file.

I just posted a routine to do something very similar, except it wrote to a
file rather than to Excel. Here's the code, below, which I modified slightly
but which you will need to finish, since you don't give many details. Copy
the code into a module in an otherwise empty workbook. The values will be
written into the activesheet.

HTH,
Bernie
MS Excel MVP

Option Explicit
Sub GetOneColumns()
Dim ResultStr As String
Dim FileName As String
Dim FileNumIn As Integer
Dim ResultsArray As Variant
Dim Counter As Double
Dim myCell As Range

Counter = 0

FileName = Application.GetOpenFilename
If FileName = "" Then End

FileNumIn = FreeFile()
Open FileName For Input As #FileNumIn

Set myCell = Range("A65536")

Do While Seek(FileNumIn) <= LOF(FileNumIn)
Counter = Counter + 1
Application.StatusBar = "Processing line " & Counter
Line Input #FileNumIn, ResultStr
ResultsArray = Split(ResultStr, vbTab)
'ResultsArray is a 0 based array of the tab-delimited values
'This example writes the second column of data into Excel
'starting in column A and moving across the worksheet
'It will write 65,500 values into each column
myCell.End(xlUp)(2).Value = ResultsArray(1)
If myCell.End(xlUp)(2).Row = 65501 Then
Set myCell = myCell(1,2)
End If
Print #FileNumOut, WholeLine
Loop

Close FileNumIn
Close #FileNumOut

Application.StatusBar = False

End Sub
 
Back
Top