+ Reply to Thread
Results 1 to 6 of 6

Macro Add line break after character

  1. #1
    Registered User
    Join Date
    06-06-2008
    Posts
    8

    Macro Add line break after character

    Hello,

    I think I have a fairly simple problem but can't find the solution. I have a column full to text strings. Each of the text strings has multiple 'substrings' of text seperated by a ";" that I would like displayed on a new line in the same cell. I know I can manually add a line break with ALT+Enter. How do I write a macro to search the entire column and add a line break (I think its "chr(10)") after each ";"

    Example:
    Current
    In Cell A1:
    Roses are red; Violets are blue; I got nothing;

    In Cell A2

    Another fake line; why aren't I creative?

    Desired
    In Cell A1
    Roses are red
    Violets are blue
    I got nothing

    In cell A2
    Anotehr fake line
    why aren't I creative?

    ***
    Thanks in advance!! (note, I don't care if the ";" is replaced by the line break or if the line break is added afterwards...

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Macro Add line break after character

    You can do it in one operation using Find & Replace. Highlight the cells that you want to change (or the complete column), then CTRL-H. Then in the Find What box type "; " without the quotes (i.e. semicolon followed by a space). In the Replace with box type a semicolon followed by CTRL-J, then click Replace All. You may need to adjust your column width.

    Hope this helps.

    Pete

  3. #3
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Macro Add line break after character

    Formula in B1 ............ =SUBSTITUTE(A1,"; ",CHAR(10))
    Elegant Simplicity............. Not Always

  4. #4
    Registered User
    Join Date
    06-06-2008
    Posts
    8

    Re: Macro Add line break after character

    AWESOME! Thanks - I knew it had to be easy. I didn't mention this earlier, but I don't think the provided solutions would quite work because the values are in a Pivot Table.

    The code I came up with is as follows - not sure its clean (and certainly not as simple as using the formulas or options)

    Please Login or Register  to view this content.
    Last edited by Tybalt; 04-30-2013 at 01:26 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Macro Add line break after character

    nice one

  6. #6
    Registered User
    Join Date
    06-06-2008
    Posts
    8

    Re: Macro Add line break after character

    Actually I'm finding this script fixes only some of the cells. I'm baffled by this... any thoughts on how I could write it better?

+ 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