+ Reply to Thread
Results 1 to 6 of 6

Merging Multiple Cells Into One Cell with exceptions

  1. #1
    Registered User
    Join Date
    08-05-2014
    Location
    Oklahoma City
    MS-Off Ver
    Office 15
    Posts
    2

    Question Merging Multiple Cells Into One Cell with exceptions

    Hi, I am obviously new to the forum and am wanting to get better with excel. This is a work project where I am trying to merge cells when there is a value the cell and append a comma and a space when the cell is not null. Example: Some cells with have data whereas some will not. In Row 1, I am trying to move name1 name2 and name3 into another cell (this I have tackled), but at the same time keep the cell grammatically correct by separating them with a comma and a space. In row 2, I am trying to move name4 and name 5 into another cell using the same above described formatting. Row 3 would just display "name6" (with no comma or space). And for row 4, I need to be displayed "name7, name8" etc etc etc.....I tried using a concatenate with an if istext, but could not get the cell to put out a value. As well, I have a little bit of programming background in C, but haven't really messed with it in some time. Half of my problem is not knowing excel's syntax. Thanks in advance. By the way, this is not homework or anything like that (I don't know what your rules are here), I am trying to shine at a new job. Again, thanks.

    a b c
    1 name1 name2 name3

    2 name4 name5

    3 name6

    4 name7 name8


    edit: this is not spacing correctly on the thread. Assume "name1" is in cell a1, "name2 is in cell b1, "name3 is in cell c1 etc, "name8" is in cell c4. Cells c2, b3, c3 and b4 are all blank. Haha, this looks a little confusing now....I guess my next question should be "how can I post in a forum with the spacing seen as I see it?"
    Last edited by dublisto; 08-05-2014 at 07:44 PM.

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Merging Multiple Cells Into One Cell with exceptions

    Welcome to the forum.

    Here is en example of how you can concatenate values from different cells into one

    =A1&" "&B1&" "&C1

    A
    B
    C
    D
    1
    name1 name2 name3 name1 name2 name3
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Merging Multiple Cells Into One Cell with exceptions

    Try this...

    Data Range
    A
    B
    C
    D
    E
    1
    name1
    name2
    name3
    ------
    name1, name2, name3
    2
    name4
    name5
    name4, name5
    3
    name6
    name6
    4
    name7
    name8
    name7, name8


    This formula entered in E1 and copied down:

    =TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1
    &","&B1&","&C1," ","~"),","," "))," ",", "),"~"," "))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    08-05-2014
    Location
    Oklahoma City
    MS-Off Ver
    Office 15
    Posts
    2

    Re: Merging Multiple Cells Into One Cell with exceptions

    Quote Originally Posted by Tony Valko View Post
    Try this...

    Data Range
    A
    B
    C
    D
    E
    1
    name1
    name2
    name3
    ------
    name1, name2, name3
    2
    name4
    name5
    name4, name5
    3
    name6
    name6
    4
    name7
    name8
    name7, name8


    This formula entered in E1 and copied down:

    =TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1
    &","&B1&","&C1," ","~"),","," "))," ",", "),"~"," "))
    The Only Problem I am having with this is that when there is only 1 name out of the three cells, it ends with a double comma (",,")
    I need it to overlook the empty cells...is there a way to state "while istext in cells b1 and or c1, display name1, name2, name3."
    There will always be something in the "a" column.

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Merging Multiple Cells Into One Cell with exceptions

    Works OK for me.

    Here's a sample file:
    Attached Files Attached Files

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Merging Multiple Cells Into One Cell with exceptions

    Here is more cells
    in H1 and copy formula down

    =SUBSTITUTE(TRIM(A1&" "&B1&" "&C1&" "&D1&" "&" "&E1&" "&F1)," ",", ")

    A
    B
    C
    D
    E
    F
    G
    H
    1
    name1 name2 name3 name1, name2, name3
    2
    name4 name6 name7 name4, name6, name7
    3
    name9 name10 name12 name13 name14 name9, name10, name12, name13, name14

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Merging Multiple Cells Into One Cell with exceptions

    I should note that the formula I suggested is more robust in that it accounts for cells that may contain either spaces or commas.

    For example:

    Data Range
    A
    B
    C
    D
    E
    1
    John Smith
    Joe Camel
    ------
    John Smith, Joe Camel
    2
    Misty Rain, Tina Fey
    Amy Long
    Misty Rain, Tina Fey, Amy Long
    3


    If your data will never have those characters then use AlKey's formula.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Merging multiple cells into a single cell with comma
    By faizaan316 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2013, 04:04 PM
  2. Merging multiple cells into one cell
    By jrg123 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-09-2013, 11:08 AM
  3. Replies: 1
    Last Post: 01-22-2013, 09:17 AM
  4. Merging cells/merging cell content.
    By rhintintin in forum Excel General
    Replies: 3
    Last Post: 09-23-2010, 10:42 AM
  5. Merging multiple cells into one.
    By kbrnhart in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-22-2010, 11:10 AM

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