+ Reply to Thread
Results 1 to 7 of 7

Separating 2 lines of text within a cell

  1. #1
    Registered User
    Join Date
    12-08-2010
    Location
    Detroit
    MS-Off Ver
    Excel 2003
    Posts
    4

    Separating 2 lines of text within a cell

    Hi, I'm wondering if there is a formula I can do in Excel to separate two lines of text that are currently within a single cell. The second line of text was originally input using the control/command key, and there are multiple words with different character lengths within each line. I need the second line of text to be cut and pasted into a separate adjacent cell so that I can convert my spreadsheet (a huge address list) into a .csv file for a mail merge.

    If there is a way to do this with a formula, please PLEASE share. Thanks!

    Examples of text within a single cell:

    Ms. Jane Doe
    Mr. John Smith

    1 North Avenue
    Apartment 2
    Last edited by katsmeow624; 12-08-2010 at 10:36 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Separating 2 lines of text within a cell

    A1: Text string
    B1: =LEFT(A1,FIND(CHAR(10),A1)-1)
    C1: =MID(A1,FIND(CHAR(10),A1)+1,LEN(A1))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-08-2010
    Location
    Detroit
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Separating 2 lines of text within a cell

    Thank you so much, that worked. One question - Is there a way to make the B1 formula conditional, so that if cells did not have a second line of text (which is the case for about 2/3 of my spreadsheet), the first and only line of text would still paste into B1 rather than "#VALUE!"?
    Last edited by katsmeow624; 12-09-2010 at 07:52 AM.

  4. #4
    Registered User
    Join Date
    12-08-2010
    Location
    Detroit
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Separating 2 lines of text within a cell

    Shoot...one more question. I just hopped on my MacBook to edit the Excel file there, and the formula doesn't work. Do you happen to know if the formula needs to be / can be altered to work on this version of Excel (Microsoft Office 2008)?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Separating 2 lines of text within a cell

    Quote Originally Posted by katsmeow624 View Post
    Is there a way to make that formula conditional, so that if cells did not have a second line of text
    A1 = text string
    B1: =IF(ISNUMBER(FIND(CHAR(10),A1)), LEFT(A1,FIND(CHAR(10),A1)-1), A1)
    C1: =IF(ISNUMBER(FIND(CHAR(10),A1)), MID(A1,FIND(CHAR(10),A1)+1,LEN(A1)), "")

    I just hopped on my MacBook to edit the Excel file there, and the formula doesn't work
    LEFT is a function in Excel Mac, too. Perhaps the CHAR() function isn't a MAC function? I couldn't comment. Try putting =CHAR(10) in a cell and see if you get an error.

  6. #6
    Registered User
    Join Date
    12-08-2010
    Location
    Detroit
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Separating 2 lines of text within a cell

    Quote Originally Posted by JBeaucaire View Post
    A1 = text string
    B1: =IF(ISNUMBER(FIND(CHAR(10),A1)), LEFT(A1,FIND(CHAR(10),A1)-1), A1)
    C1: =IF(ISNUMBER(FIND(CHAR(10),A1)), MID(A1,FIND(CHAR(10),A1)+1,LEN(A1)), "")
    ]
    LEFT is a function in Excel Mac, too. Perhaps the CHAR() function isn't a MAC function? I couldn't comment. Try putting =CHAR(10) in a cell and see if you get an error.
    THANKS! That worked perfectly on the PC version but not on the Mac.

    On the Mac, =CHAR(10) results in a blank text box. The new conditional formulas caused the text in column B to look exactly the same as column A, except there is a space between the two lines of text and no second line. And column C is blank. Any idea why?
    Last edited by katsmeow624; 12-09-2010 at 03:00 PM.

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Separating 2 lines of text within a cell

    Where did the source data come from?
    If it was from the web there is a fair chance that CHAR(160) is the line separator.

+ 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