+ Reply to Thread
Results 1 to 11 of 11

Combinding sevral rows into one row with "-"in betwin if not blank

  1. #1
    Registered User
    Join Date
    02-21-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    5

    Combinding sevral rows into one row with "-"in betwin if not blank

    Hei.

    I need to get cell A2, C2 and E2 combined into F2 with "-".
    But if lets say C2 is empty I dont want the "-"

    ****************************
    exempel 1:
    A2:F08
    C2:31
    E2:XXL

    the result in F2should be:
    F08-31-XXL
    *****************************
    exempel 2:
    A2:F08
    C2:
    E2:XXL

    the result in F2should be:
    F08-XXL
    *****************************
    An exampel on how it should not be:

    A2:F08
    C2:
    E2:XXL

    the result in F2should be:
    F08--XXL
    *****************************

  2. #2
    Registered User
    Join Date
    02-21-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    I have tryed =A2&"-"&C2&"-"&E2 but then i get the result: F08--XXL

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    Try:

    =SUBSTITUTE(A2&"-"&C2&"-"&E2,"--","-")

  4. #4
    Registered User
    Join Date
    02-21-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    Almost there:-)
    Thanx zbor for the replay.
    I had to change it to =SUBSTITUTE(A2&"-"&C2&"-"&E2;"--";"-") not to get an error.
    Now all is ok:-) except if there is only data in A2 and C2 and E2 is blank I get F08-

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    How about this:

    =LEFT(SUBSTITUTE(SUBSTITUTE(A2&C2&E2;A2;A2&"-");C2;C2&"-");2*LEN(A2)+2*LEN(C2)+2*LEN(E2)-1)

    If you don't have same fords in A2, C2 and E2 cells. (or part of the words as TE, TES, TEST)
    Last edited by zbor; 02-26-2012 at 07:59 AM.

  6. #6
    Registered User
    Join Date
    02-21-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    Mayby this will help explaine what I am trying to do.
    Capture.PNG
    The product name in F2 should be F02001-87 not F02001-87-
    and the product name in F3 Should be F08097 not F08097-

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    Try now, I've edited...

    Also, instead of picture it's better to upload xls workbook (this is a excel forum not a piant forum )

  8. #8
    Valued Forum Contributor
    Join Date
    03-20-2011
    Location
    UK
    MS-Off Ver
    Excel 2007/10/16
    Posts
    840

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    Hi

    Only way to work is do a the simple job and simple code
    .
    Here put on your workbook.

    G2 =IF($C2="","","-")
    H2 =IF($E2="","","-")
    You can hide them.

    Then F2 =$A2&G2&C2&H2&E2

    Unless zbor come up with better code.

    Cheers
    Last edited by micope21; 02-26-2012 at 12:34 PM.

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    You can use that but in one cell:

    =A2&IF(A2="";"";"-")&C2&IF(C2="";"";"-")&E2&IF(E2="";"";"-")

  10. #10
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    you could try one of these options

    =A1&IF(C1="","","-")&C1&IF(E1="","","-")&E1

    =LEFT(SUBSTITUTE(A1&"-"&C1&"-"&E1,"--","-"),LEN(A1)+LEN(C1)+LEN(E1)+COUNTA(A1,C1,E1)-1)
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  11. #11
    Registered User
    Join Date
    02-21-2012
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Combinding sevral rows into one row with "-"in betwin if not blank

    Thanx
    =LEFT(SUBSTITUTE(A2&"-"&C2&"-"&E2;"--";"-");LEN(A2)+LEN(C2)+LEN(E2)+COUNTA(A2;C2;E2)-1)

    did the trick :-)

    Best forum ever:-)

+ 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