+ Reply to Thread
Results 1 to 19 of 19

Concatenate cells with 5 characters each column but ignore if blank

  1. #1
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Concatenate cells with 5 characters each column but ignore if blank

    Hi all,

    good morning! I'm in need of help to figure out how to concatenate columns by a dash with 5 character each column but if the column is empty the formula must ignore move on to the next column.


    Columns a | b | c | d | e | f | g | h |

    this is how it should be concatenated and please note the length value inside the column should 5 so i need automatic leading zero if my value each col is less than 5:

    Column grouping: A-b | c-d | e-f | g-h

    a | b | c | d | e | f | g | h |
    blk1 | blk2 | blk3 | | blk5 | blk6 | blk7 | |

    output should be: 0blk1-0blk2 0blk3 0blk5-0blk6 0blk7

    please help!

  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,926

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Hi and welcome to the forum

    Sometimes, when you copy/paste your data into here, it doesnt come out quite the way you intended I suggest you upload this in a dummy workbook

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    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
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Concatenate.xlsx

    I'm sorry. Here you go... Thank you!

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Concatenate cells with 5 characters each column but ignore if blank

    First attempt
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(A3&" "&B3&"^"&C3&" "&D3&"^"&E3&" "&F3&"^"&G3&" "&H3)," ","-"),"-^"," "),"^"," "),"BLK","0BLK")
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    I apologize for not being clear. Actually "BLK" is just one of the words on spreadsheet. It could be any word or data.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Concatenate cells with 5 characters each column but ignore if blank

    It's not pretty but

    =SUBSTITUTE(TRIM(SUBSTITUTE(TRIM(REPT("0",5-LEN(A3))&A3&" " & REPT("0",5-LEN(B3))&B3&" " &REPT("0",5-LEN(C3))&C3&" " &REPT("0",5-LEN(D3))&D3&" " &REPT("0",5-LEN(E3))&E3&" " &REPT("0",5-LEN(F3))&F3&" " &REPT("0",5-LEN(G3))&G3 &REPT("0",5-LEN(H3))&H3),"00000", ""))," ","-")
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Concatenate cells with 5 characters each column but ignore if blank

    yea i stopped for dinner and came up with
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(REPT("0",IF(5-LEN(A3)=5,0,5-LEN(A3)))&A3&" "&REPT("0",IF(5-LEN(B3)=5,0,5-LEN(B3)))&B3&"^"&REPT("0",IF(5-LEN(C3)=5,0,5-LEN(C3)))&C3&" "&REPT("0",IF(5-LEN(D3)=5,0,5-LEN(D3)))&D3&"^"&REPT("0",IF(5-LEN(E3)=5,0,5-LEN(E3)))&E3&" "&REPT("0",IF(5-LEN(F3)=5,0,5-LEN(F3)))&F3&"^"&REPT("0",IF(5-LEN(G3)=5,0,5-LEN(G3)))&G3&" "&REPT("0",IF(5-LEN(H3)=5,0,5-LEN(H3)))&H3)," ","-"),"-^"," "),"^"," ")

  8. #8
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Still not working when I removed a value on one column it combines it with another column.
    A-B should be concatenated together and B-C should always have a space in between and not a dash if one cell if empty. Notice how 0BLK6-0BLK7 got combined together? it should have been 0BLK6 0BLK7

    Result of the formula: 0BLK1-0BLK2-0BLK3-0BLK5-0BLK6-0BLK7

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Concatenate cells with 5 characters each column but ignore if blank

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(REPT("0",IF(5-LEN(A3)=5,0,5-LEN(A3)))&A3&" "&REPT("0",IF(5-LEN(B3)=5,0,5-LEN(B3)))&B3&"^"&REPT("0",IF(5-LEN(C3)=5,0,5-LEN(C3)))&C3&" "&REPT("0",IF(5-LEN(D3)=5,0,5-LEN(D3)))&D3&"^"&REPT("0",IF(5-LEN(E3)=5,0,5-LEN(E3)))&E3&" "&REPT("0",IF(5-LEN(F3)=5,0,5-LEN(F3)))&F3&"^"&REPT("0",IF(5-LEN(G3)=5,0,5-LEN(G3)))&G3&" "&REPT("0",IF(5-LEN(H3)=5,0,5-LEN(H3)))&H3)," ","-"),"-^"," "),"^"," ")," -"," ") thats about it the formula gets too long otherwise
    or put that in i3 then in j3 =trim(i3)
    Last edited by martindwilson; 08-30-2013 at 05:31 PM.

  10. #10
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Sorry but the formula doesn't work

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Concatenate cells with 5 characters each column but ignore if blank

    post a workbook where it doesnt work

  12. #12
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Sorry, it did work this time. I must have copied an extra space. Just wanted to understand your formula what's the ^ for? and also, is there a way the extra spaces at the end of the formula be removed instead of the additional =trim() formula?

    Thank you very much for all your help! really really really appreciate it!

  13. #13
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Concatenate cells with 5 characters each column but ignore if blank

    not in 2003 the formula is at its max length if you try to add trim to it it doesn't work

  14. #14
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    How about for 2010? Do you mind helping me with 2010 version?

  15. #15
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Concatenate cells with 5 characters each column but ignore if blank

    I haven't got 2010 but try wRaping it in trim

  16. #16
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Alternate:

    =SUBSTITUTE(RIGHT("00000"&A3,5)&"-"&RIGHT("00000"&B3,5)&" "&RIGHT("00000"&C3,5)&"-"&RIGHT("00000"&D3,5)&" "&RIGHT("00000"&E3,5)&"-"&RIGHT("00000"&F3,5)&" "&RIGHT("00000"&G3,5)&"-"&RIGHT("00000"&H3,5),"-00000","")
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  17. #17
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    @martindwilson - you are awesome! you just made my life easier! You were a great help! thank you so much!

  18. #18
    Registered User
    Join Date
    09-07-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Concatenate cells with 5 characters each column but ignore if blank

    Hello @Martindwilson...

    I'm going to revive the formula you helped me with back in 2013 -- I just wanted to understand the use of "^"? Can you please help?

    =TRIM(CONCATENATE("CAVENT:",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(REPT("0",IF(4-LEN(F2)=4,0,4-LEN(F2)))&F2&"^"&W2&"-"&REPT("0",IF(5-LEN(X2)=5,0,5-LEN(X2)))&X2&"^"&REPT("0",IF(3-LEN(BP2)=3,0,3-LEN(BP2)))&BP2&"^"&REPT("0",IF(5-LEN(BR2)=5,0,5-LEN(BR2)))&BR2&" "&REPT("0",IF(5-LEN(BS2)=5,0,5-LEN(BS2)))&BS2&"^"&REPT("0",IF(5-LEN(BT2)=5,0,5-LEN(BT2)))&BT2&" "&REPT("0",IF(5-LEN(BU2)=5,0,5-LEN(BU2)))&BU2&"^"&REPT("0",IF(5-LEN(BV2)=5,0,5-LEN(BV2)))&BV2&" "&REPT("0",IF(5-LEN(BW2)=5,0,5-LEN(BW2)))&BW2&"^"&REPT("0",IF(4-LEN(BX2)=4,0,4-LEN(BX2)))&BX2&" "&REPT("0",IF(4-LEN(BY2)=4,0,4-LEN(BY2)))&BY2)," ","-"),"-^"," "),"^"," ")," -"," ")))

  19. #19
    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: Concatenate cells with 5 characters each column but ignore if blank

    Quote Originally Posted by ghiegomez View Post
    Hello @Martindwilson...

    I'm going to revive the formula you helped me with back in 201...
    No, you are not. As this is over 7 years old, please start a new thread, and reference this thread if necessary

+ 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. How can I make a macro ignore blank cells? - Blank Cells have formulas
    By mz1161 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2013, 08:54 AM
  2. Modifying an existing module that outputs csv from column to ignore blank cells
    By spikedog in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-23-2013, 11:50 AM
  3. Average the last 10 cells of a dynamic column but ignore blank cells & 0
    By mattadler22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-13-2013, 11:37 PM
  4. Concatenate Cells and Count Characters
    By Jetheat in forum Excel General
    Replies: 8
    Last Post: 03-29-2010, 11:23 AM
  5. Ignore blank cells
    By bmunoz64 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-31-2009, 11:52 AM

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