+ Reply to Thread
Results 1 to 8 of 8

Combining Fields without getting extra spaces or semi-colons

  1. #1
    Registered User
    Join Date
    07-05-2013
    Location
    Ohio, US
    MS-Off Ver
    Excel 2013
    Posts
    32

    Combining Fields without getting extra spaces or semi-colons

    I'm trying to combine text data from 8 fields into one and separate them with a semi colon and a space. This formula works well....

    =K2&"; "&L2&"; "&M2&"; "&N2&"; "&O2&"; "&P2&"; "&Q2&"; "&R2

    ....except when there are blank fields it still enters "; ". In the extreme example, if all the fields are blank I end up getting ";;;;;;;;". Ideally, I don't want these extra semi colons or spaces if there is a blank field.

    Any thoughts?

  2. #2
    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,946

    Re: Combining Fields without getting extra spaces or semi-colons

    maybe this brute-force version...
    =IF(K2="","",K2&"; ")&IF(L2="","",L2&"; ")&IF(M2="","",M2&"; ")&IF(N2="","",N2&"; ")&IF(O2="","",O2&"; ")&IF(P2="","",P2&"; ")&IF(Q2="","",Q2&"; ")&R2
    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

  3. #3
    Registered User
    Join Date
    07-05-2013
    Location
    Ohio, US
    MS-Off Ver
    Excel 2013
    Posts
    32

    Re: Combining Fields without getting extra spaces or semi-colons

    FDibbins - Wow! Maybe "brute-force" to you but a think of beauty to me. Thank you!

  4. #4
    Registered User
    Join Date
    07-05-2013
    Location
    Ohio, US
    MS-Off Ver
    Excel 2013
    Posts
    32

    Re: Combining Fields without getting extra spaces or semi-colons

    BTW, is there a way to do this without adding a semi colon or space after the last value? As an example, in FDibbins version....

    =IF(K2="","",K2&"; ")&IF(L2="","",L2&"; ")&IF(M2="","",M2&"; ")&IF(N2="","",N2&"; ")&IF(O2="","",O2&"; ")&IF(P2="","",P2&"; ")&IF(Q2="","",Q2&"; ")&R2

    ..... if "Ohio" was in one of the eight fields and the other seven fields were blank, it would return "Ohio; ". Just wondering how it could be done without having a "; " at the end of the last value.

  5. #5
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Combining Fields without getting extra spaces or semi-colons

    Try..

    =SUBSTITUTE(TRIM(K2&" "&L2&" "&M2&" "&N2&" "&O2&" "&P2&" "&Q2&" "&R2)," ","; ")
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  6. #6
    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,946

    Re: Combining Fields without getting extra spaces or semi-colons

    Or this slight variation (told you it was brute-force lol)....
    =K2&IF(K2="","","; ")&L2&IF(L2="","","; ")&M2&IF(M2="","","; ")&N2&IF(N2="","","; ")&O2&IF(O2="","","; ")&P2&IF(P2="","","; ")&Q2&IF(Q2="","","; ")&R2

  7. #7
    Registered User
    Join Date
    07-05-2013
    Location
    Ohio, US
    MS-Off Ver
    Excel 2013
    Posts
    32

    Re: Combining Fields without getting extra spaces or semi-colons

    Ace_XL - Sweet! Thanks!

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Combining Fields without getting extra spaces or semi-colons

    If it is allowed with an helpcolumn you can solve it like in the attached file.
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

+ 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