Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Topje
 
Posts: n/a
Default How to import a TXT with strings containing enters into Excel?

I want to import a .txt into Excel. One item is a string which contains enters.

example:

00.001;"text wich contains an enter
and continues on the next row one
or more times";
00.002;"text without enters is imported correctly";

I want excel to put the entire string into one cell.
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

I think I'd do a little preprocessing on the file.

Option Explicit
Sub testme()

Dim iFileName As Variant
Dim oFileName As String

Dim iFileNum As Long
Dim oFileNum As Long

Dim myLine As String
Dim myPrevLine As String

iFileName = Application.GetOpenFilename("Text Files, *.txt")

If iFileName = False Then
Exit Sub 'user hit cancel
End If

oFileName = Left(iFileName, Len(iFileName) - 4) & ".OUT"

iFileNum = FreeFile
Close iFileNum
Open iFileName For Input As iFileNum

oFileNum = FreeFile
Close oFileNum
Open oFileName For Output As oFileNum

Do While Not EOF(iFileNum)
Line Input #iFileNum, myLine
If myPrevLine = "" Then
myPrevLine = myLine
Else
If Left(myLine, 6) Like "##?###" Then
Print #oFileNum, myPrevLine
myPrevLine = myLine
Else
myPrevLine = myPrevLine & " " & myLine
End If
End If
Loop

'write the last output row
Print #oFileNum, myPrevLine

Close #iFileNum
Close #oFileNum
End Sub


This creates a .OUT file that can be imported the way you wanted.

Another option would be to import the file the way excel does it, then
manipulate the data within excel--kind of a 6 of one/half dozen of the other.

Topje wrote:

I want to import a .txt into Excel. One item is a string which contains enters.

example:

00.001;"text wich contains an enter
and continues on the next row one
or more times";
00.002;"text without enters is imported correctly";

I want excel to put the entire string into one cell.


--

Dave Peterson
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
Text import wizard defaults? Bruce Bowler Excel Discussion (Misc queries) 4 April 3rd 23 10:57 AM
Import comma delimited text Lin Excel Discussion (Misc queries) 3 July 28th 06 04:07 PM
Import Excel Data from another workbook or file tamato43 Excel Discussion (Misc queries) 1 February 28th 05 05:26 PM
Compare cells/columns and highlight matching text strings luxbelle Excel Worksheet Functions 1 February 25th 05 06:34 PM
Automatic Data Import TxRaistlin Excel Discussion (Misc queries) 2 February 4th 05 10:43 PM


All times are GMT +1. The time now is 09:45 AM.

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"