Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Importing Text file (Again)

Hi all
Joel Help me with this, but finally I find another bug
When try to imported a large file(more 65300 lines), the data imported in the
second sheet come in one column, Here the final code:
Thanks for your support
Dante

Sub LargeFileImport()
'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
Dim Filt As String
Dim FilterIndex As Integer
Dim Titre As String

Filt = "Text File (*.txt),*.txt," & _
"Fichiers CSV (*.csv),*.csv,"

'Ask User for File's Name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Titre)
'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

If ActiveCell.Row = Rows.Count Then
'If On The Last Row Then Add A New Sheet
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False
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
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False

'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Importing Text file (Again)

this doesn't make sense. Try starting with a blank worksheet and run the
code again. I'm thinking that the last sheet that wasn't split was imported
before you made the final changes.



"Dante Huapaya" wrote:

Hi all
Joel Help me with this, but finally I find another bug
When try to imported a large file(more 65300 lines), the data imported in the
second sheet come in one column, Here the final code:
Thanks for your support
Dante

Sub LargeFileImport()
'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
Dim Filt As String
Dim FilterIndex As Integer
Dim Titre As String

Filt = "Text File (*.txt),*.txt," & _
"Fichiers CSV (*.csv),*.csv,"

'Ask User for File's Name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Titre)
'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

If ActiveCell.Row = Rows.Count Then
'If On The Last Row Then Add A New Sheet
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False
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
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False

'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Importing Text file (Again)

This doesn't make senese. I would start with a clean workbook and try again.
I suyspect that the sheet theat isn't split into multiple columns was left
over in you r workbook before you made the last set of changes to your code.

"Dante Huapaya" wrote:

Hi all
Joel Help me with this, but finally I find another bug
When try to imported a large file(more 65300 lines), the data imported in the
second sheet come in one column, Here the final code:
Thanks for your support
Dante

Sub LargeFileImport()
'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
Dim Filt As String
Dim FilterIndex As Integer
Dim Titre As String

Filt = "Text File (*.txt),*.txt," & _
"Fichiers CSV (*.csv),*.csv,"

'Ask User for File's Name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Titre)
'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

If ActiveCell.Row = Rows.Count Then
'If On The Last Row Then Add A New Sheet
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False
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
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False

'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Importing Text file (Again)

Hi Joel,
the problem come from my text file, please try to import this:
Thanks Again
SAR POL 20080101-POL 2008 10556673 FOOT 01/05/08 EURO2000 T085
3.132807-
SAR POL 20071115-POL 2008 10556673 FOOT 01/05/08 EURO2000 T085
3.313641-
SAR POL 20071129-POL 2008 10556673 FOOT 01/05/08 EURO2000 T085
3.304700-
SAR POL 20071213-POL 2008 10556673 FOOT 01/05/08 EURO2000 T085
3.302472-




"Joel" wrote:

This doesn't make senese. I would start with a clean workbook and try again.
I suyspect that the sheet theat isn't split into multiple columns was left
over in you r workbook before you made the last set of changes to your code.

"Dante Huapaya" wrote:

Hi all
Joel Help me with this, but finally I find another bug
When try to imported a large file(more 65300 lines), the data imported in the
second sheet come in one column, Here the final code:
Thanks for your support
Dante

Sub LargeFileImport()
'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
Dim Filt As String
Dim FilterIndex As Integer
Dim Titre As String

Filt = "Text File (*.txt),*.txt," & _
"Fichiers CSV (*.csv),*.csv,"

'Ask User for File's Name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Titre)
'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

If ActiveCell.Row = Rows.Count Then
'If On The Last Row Then Add A New Sheet
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False
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
Columns("A:A").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlFixedWidth, _
ConsecutiveDelimiter:=False, _
Comma:=False

'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing CSV file (saved as Text) into XL as Text -- over 60 colu sbp Excel Discussion (Misc queries) 1 October 14th 06 11:50 PM
Importing text file, only option to edit existing file smokey99 Excel Discussion (Misc queries) 8 April 26th 06 09:08 PM
Importing text file Jeff Excel Discussion (Misc queries) 1 April 4th 06 01:45 PM
Importing text file Jillianno Excel Discussion (Misc queries) 1 February 16th 05 06:47 PM
importing text file, removing data and outputting new text file Pal Excel Programming 8 February 27th 04 08:32 PM


All times are GMT +1. The time now is 09:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"