+ Reply to Thread
Results 1 to 8 of 8

Excel Macro merge cell contents and separate by soft return

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    16

    Post Excel Macro merge cell contents and separate by soft return

    Please Login or Register  to view this content.
    Test.xls
    Please Login or Register  to view this content.
    I am trying to put together a macro that will:
    1. Merge the contents from two cells together (i.e., C3:C4 merged into C3)
    2. Separate the contents with a soft return in the merged cell

    The contents or values do not need to be added, as in 1+1 = 2. The values need to remain separate.
    I found a method to merge the two cells, but it deletes the contents from the second cell.

    Is there a way to merge the two cells, or copy the contents from C4 into C3 and keep the contents separated by a soft return?

    Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Excel Macro merge cell contents and separate by soft return

    Hi, WesternGal,

    merging cells means putting the cells together into one cell - you will have only one cell physically which stretches across two cells.

    Maybe this code will lead you into the direction where you want to go. As it is working with ActiveCell please choose cell C3 before you run the code:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Excel Macro merge cell contents and separate by soft return

    Holger,

    Thanks for the reply. I'm not really sure where to go with this code; it gives me a message box, but doesn't merge the contents.

    I recorded a macro to see if I could build off what I needed.


    Please Login or Register  to view this content.
    However, I wanted something that would copy/paste the cell contents, not a specified number since each table will have different values. I came up with this, but it does not keep the formatting, although it did in the above macro. (i.e., a 14% becomes .14)
    Please Login or Register  to view this content.
    Is there any way to keep the formatting? Or should I repost as a separate question?

    Thanks,
    Western Gal

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Excel Macro merge cell contents and separate by soft return

    Hi, WesternGal,

    still donīt get for which range this action should be taken. The difference bvetween your recorded macro and the sniplet is that you take the value and my code relates on what is shown in the cell.

    To paste the contents into the active cell use
    Please Login or Register  to view this content.
    The code will place the contents to the left of the cell (as this is a string thatīs put in) and it doesnīt change the formatting when I use it with Excel2013.

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    05-17-2013
    Location
    South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Excel Macro merge cell contents and separate by soft return

    Holger,

    The code worked! Thanks for your help.

    WesternGal

  6. #6
    Registered User
    Join Date
    05-17-2013
    Location
    South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Excel Macro merge cell contents and separate by soft return

    One final note for those newbies like myself . . . I didn't want to have to select a cell each time I need to merge cells since I have several tables, I added a line to select the cell, then combine the contents. Of course, this only works since the info is always in the set cells.
    Please Login or Register  to view this content.
    Last edited by WesternGal; 05-20-2013 at 10:08 PM.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Excel Macro merge cell contents and separate by soft return

    Hi, WesternGal,

    maybe use these instead of changing the range for each individual cell, first uses a given range, second needs you to choose the range on which it should work prior to running the macro:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    05-17-2013
    Location
    South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Excel Macro merge cell contents and separate by soft return

    Thanks -- worked beautifully!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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