+ Reply to Thread
Results 1 to 10 of 10

Combining Cells into One Cell

  1. #1
    Registered User
    Join Date
    09-16-2009
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question Combining Cells into One Cell

    Hi, all.
    I am trying to combine multiple cells into 1 cell per row.
    I would have "A" column empty, then combine "B", "C", and on into the "A" column.
    Each cell value will be separated by a space or any special character I designate in the macro

    I have attached an example which the output is separated by a space.
    Sheet1 has the original file and Sheet2 has the desired output.
    Thank you for all your help in advance.
    Attached Files Attached Files

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

    Re: Combining Cells into One Cell

    KrNpRiDe,

    Try:

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Adding the Macro
    1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel


    Please Login or Register  to view this content.

    Then run the "CombineText" macro.
    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
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Combining Cells into One Cell

    Here is another version that will size the range automatically. It is set to put the combined data into column "A". You are prompted for the separator when the macro runs. This can be hard coded if you like. A button has been added to the worksheet to run the macr.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    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!)

  4. #4
    Registered User
    Join Date
    09-16-2009
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Combining Cells into One Cell

    Thank you all for fast response.

    stanleydgromjr, your code only works for 3 column field, but works great for for that purpose.

    Leith Ross, your code works great, but gives an error message:

    "Run-time error '1004': Application-defined or object-defined error"
    The line in the code is "Rng.value = Data"

    I believe the error occurs due to the range of column is not changing.

    How can I make the number of columns change for every row?

    Thank you.

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

    Re: Combining Cells into One Cell

    Hello KrNpRiDe,

    The macro I wrote is attached to the workbook (Excel 2003 format) in my previous. Since there have been no downloads of the file, I would suggest you do so. The problem maybe version related. Your profile says you are using Excel 2007. Download the workbook that has the macro and see how it performs on your system.

  6. #6
    Registered User
    Join Date
    09-16-2009
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Combining Cells into One Cell

    Thanks Leith Ross.

    I have tried your code with the file that you provided.
    The number of column stays constant through out the program.
    I need it to be variant per each row.
    I have changed the sample file and attached it below.
    Please let me know how I can change the number of columns for each row.

    Thank you in advance.

  7. #7
    Registered User
    Join Date
    09-16-2009
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Combining Cells into One Cell

    Sorry, forgot add the attachment.

  8. #8
    Registered User
    Join Date
    09-16-2009
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Combining Cells into One Cell

    Sorry, new to this forum. File attached.
    Attached Files Attached Files

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

    Re: Combining Cells into One Cell

    Try this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    09-16-2009
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Combining Cells into One Cell

    Thank you shg.

    Your code worked perfectly.

    Thank you all for great help and fast responses.

+ 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