+ Reply to Thread
Results 1 to 9 of 9

Excel 2010 Concatenate If statement

  1. #1
    Registered User
    Join Date
    03-29-2013
    Location
    Phx, Az
    MS-Off Ver
    Excel 2010
    Posts
    4

    Unhappy Excel 2010 Concatenate If statement

    Hello guys,

    I have been puzzled by the following formula for far too long.

    I have about 10 columns of possible data all of which have at least 2 words. I need to concatenate these rows into a comma separate list.

    I tried: =SUBSTITUTE(TRIM(G2 & " " & H2 & " " & I2 & " " & J2 & " " & K2 & " " & L2 & " " & M2 & " " & N2 & " " & O2 & " " & P2& " " & Q2), " ", ", ")

    This works well if we only have a space between cell values and you only look to SUBSTITUTE for a single space. I realize now it is because of TRIM()... TRIM is removing the double space to just a single space between each cell value therefore SUBSTITUTE is not finding a double space to replace. I know there has to be a way around this using a formula. What are your thoughts?

    Type 1 Type 2 Type 3 Type 4 Type 5
    Type 1 Type 3
    Type 1 Type 5

    Current Answer for Row1: Type 1 Type 2 Type 3 Type 4 Type 5
    Answer desired for Row1: Type 1, Type 2, Type 3, Type 4, Type 5

    Current Answer for Row2: Type 1 Type 3
    Answer desired for Row2: Type 1, Type 3

    Current Answer for Row3: Type 1 Type 5
    Answer desired for Row3: Type 1, Type 5

    Thanks for the help!
    Last edited by Coues; 03-29-2013 at 05:33 PM. Reason: SOLVED

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

    Re: Excel 2010 Concatenate If statement

    Are you open to using a VBA function to do this?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    03-29-2013
    Location
    Phx, Az
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel 2010 Concatenate If statement

    If at all possible I would like to avoid VBA. But if I can't I guess I will have to turn to it.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Excel 2010 Concatenate If statement

    Hi

    This is messy, but it avoids VBA. Copy this down and across as many columns as you have "Types". You can hide all but he last culumn if you want...

    =IF(A1="",F1,F1&A1&IF(COUNTA(B$1:$E1)>0,", ",""))

    Adjust ranges as needed
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    03-29-2013
    Location
    Phx, Az
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel 2010 Concatenate If statement

    That is getting closer... for some reason I still have a trailing ','. Any suggestions on this?

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

    Re: Excel 2010 Concatenate If statement

    Kind of ugly but it works (as long as the data does not contain commas)...

    =SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE
    (SUBSTITUTE(G2&","&H2&","&I2&","&J2&","&K2&","&L2
    &","&M2&","&N2&","&O2&","&P2&","&Q2,
    " ","~"),","," "))," ",", "),"~"," ")

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Excel 2010 Concatenate If statement

    oops sorry, use this...

    =IF(A1="",F1,F1&A1&IF(COUNTA(A1:$E1)>1,", ",""))

  8. #8
    Registered User
    Join Date
    03-29-2013
    Location
    Phx, Az
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel 2010 Concatenate If statement

    Tony,

    EXACTLY! I just needed to take it a couple steps further! Thank you!

    Dibbins, this worked as well but takes toooo many columns in my case.

    Thank you guys for all the work!

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

    Re: Excel 2010 Concatenate If statement

    You're welcome. Thanks for the feedback!

+ 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