+ Reply to Thread
Results 1 to 6 of 6

new line within cell text

Hybrid View

  1. #1
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Perth, WA, Australia
    MS-Off Ver
    Office 365
    Posts
    249

    new line within cell text

    I am unsure which category to post this in, and so am cross posting this question under Excel General also.

    When I want to force a new line within a cell, I can do it as I am typing by hitting alt-Enter. No problem.

    However, if I want to do it programmatically, I would expect CHAR(10) to cause a line break. If not that then CHAR(13)&CHAR(10). However, no combination of these characters seems to enforce the line break; they just produce a continuous line of output with little rectangles where the unprintable characters appear.

    My question: how do I enforce a new line programmatically within the text of a cell?
    Last edited by ffffloyd; 07-13-2011 at 08:38 PM. Reason: answered by shg

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: new line within cell text

    ffffloyd,

    Try:

    
    Range("A1") = "new" & Chr(10) & "line" & Chr(10) & "within" & Chr(10) & "cell" & Chr(10) & "text"
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: new line within cell text

    Chr(10) works for me

    ActiveCell.Value = "test" & Chr(10) & "testing"
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  4. #4
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Perth, WA, Australia
    MS-Off Ver
    Office 365
    Posts
    249

    Re: new line within cell text

    Ahh, no. I didn't mean using VBA. I meant within the context of a worksheet cell. CHR is not available there; CHAR is the worksheet equivalent.

  5. #5
    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: new line within cell text

    If not that then CHAR(13)&CHAR(10). However, no combination of these characters seems to enforce the line break; they just produce a continuous line of output with little rectangles where the unprintable characters appear.
    Excel ignore carriage returns (CHAR(13)); use line feeds (CHAR(10)) and format the cell to wrap text.
    Last edited by shg; 07-13-2011 at 11:53 PM.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Perth, WA, Australia
    MS-Off Ver
    Office 365
    Posts
    249

    Re: new line within cell text

    Thanks, shg; formatting the cell to wrap text does the trick. It even works if the text is short enough to fit into the cell without necessarily wrapping.

+ 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