+ Reply to Thread
Results 1 to 7 of 7

Ignoring CR when importing txt file

  1. #1
    Registered User
    Join Date
    09-16-2008
    Location
    Ottawa, Canada
    Posts
    29

    Ignoring CR when importing txt file

    I am trying to figure out how to import a tab delimited .txt file that will have quoted fields that will have CRs within them. Whenever I try to import, Excel breaks up the lines when it encounters a CR in the middle of a quoted field. I need the line to stay in tact. Any help is appreciated.

    If I open the .txt file in notepad and select all and then copy it into Excel, I get what I want. The problem is when I open the file in Excel and try to use the delimiters and text qualifiers. That's when Excel splits quoted fields into different lines when it encounters CRs.

    I have attached a sample input file and what the desired results should be. Notice that some of the cells have multiple lines in them.

    Here is the code I was using to start with:
    Please Login or Register  to view this content.
    Thanks in advance
    Attached Files Attached Files
    Last edited by Bytor47; 09-17-2010 at 12:23 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Ignoring CR when importing txt file

    Hello Bytor47,

    After the text has been imported, you can run this macro to remove the carriage return characters.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-16-2008
    Location
    Ottawa, Canada
    Posts
    29

    Re: Ignoring CR when importing txt file

    Thanks for the reply but I can't do it that way. I am actually trying to add to an existing macro that will work with the data once it is imported.

    I need the carriage returns where they are. I just don't want the import to split the data into separate lines. I want the cells to retain the soft carriage returns in them.

    The data in the input file contains "" fields that may contain CRs that I want to keep. Excel keeps splitting those fields into different lines on me but I don't want that.

    Thanks again

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Ignoring CR when importing txt file

    Hello Bytor47,

    Excel will make a new line in a cell when a carriage return is present in the text. I don't see any new lines (columns or rows) created by importing the text. So, I don't understand what you mean by this statement...
    I need the carriage returns where they are. I just don't want the import to split the data into separate lines. I want the cells to retain the soft carriage returns in them.

  5. #5
    Registered User
    Join Date
    09-16-2008
    Location
    Ottawa, Canada
    Posts
    29

    Re: Ignoring CR when importing txt file

    What I mean is that if you look in the input file on the 4th line you will see the date and time contains a special character between them. Upon further investigation this is a LF character (Hex 0A). During my import, the macro I created ignores the fact that the LF is between quotes and splits that field over multiple lines. I don't want that to happen.

    I need all of the text, including special characters, within the quotes to remain in 1 cell.

    If I open the input file in notepad and select all the text and copy it into a blank worksheet, it pastes the way I want. The cell containing the Date and Time will actually contain 5 lines in it.

    Unfortunately I can't seem to get my macro to import the same way.

    I hope this helps.

    Thanks

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Ignoring CR when importing txt file

    They're line feeds, not carriage returns. Try
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    09-16-2008
    Location
    Ottawa, Canada
    Posts
    29

    Re: Ignoring CR when importing txt file

    That worked great. Thanks.

    Who knew 4 little characters could make such a difference when opening a .txt file.

    Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1