+ Reply to Thread
Results 1 to 16 of 16

After concatenateing need to get rid of last comma

  1. #1
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    After concatenateing need to get rid of last comma

    We have 8 columns. The amount of cells with data in it varies anywhere from one cell to all 8 cells. We would like to combine the data in all 8 with a comma and space in between each one but no commas for those cells that don't have data. We also would like to add an "&" before the last one (replacing the comma).

    We used this VBA to add the commas to the end of each individual cell:

    Please Login or Register  to view this content.
    We then did concatenate for all 8 cells which pulled it all together into one. We are stuck at how to get rid of the last comma (at the end) and how to replace the second to last comma with the &.

    Right now it comes out something like this:

    Data 1, Data 2, Data 3, Data 4, Data 5, Data 6, Data 7, Data 8,

    We would like it:

    Data 1, Data 2, Data 3, Data 4, Data 5, Data 6, Data 7 & Data 8

    We would appreciate help with this
    Last edited by needurhelp; 06-22-2014 at 11:11 PM.

  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
    53,048

    Re: need help with finishing off a formula

    Hi and welcome to the forum

    Thanks for the title change
    Last edited by FDibbins; 06-22-2014 at 11:47 PM.
    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
    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
    53,048

    Re: need help with finishing off a formula

    If your data ia in A1, try this in B1...
    =SUBSTITUTE(LEFT(A1,LEN(A1)-1),","," &",LEN(A1)-LEN(SUBSTITUTE(A1,", "," ")))

  4. #4
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    Re: After concatenateing need to get rid of last comma

    Hi,

    The formula you posted works great, but where there is only 1 data cell it doesn't seem to work I get a message #VALUE! I don't know the reason why.

    Thank you for your help.

  5. #5
    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
    53,048

    Re: After concatenateing need to get rid of last comma

    OK use this instead...
    =IFERROR(SUBSTITUTE(LEFT(A2,LEN(A2)-1),","," &",LEN(A2)-LEN(SUBSTITUTE(A2,", "," "))),A2)

    If that still does not work, can you post a sample of when it doesnt work please?

  6. #6
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: After concatenateing need to get rid of last comma

    Try this
    Please Login or Register  to view this content.
    Last edited by kvsrinivasamurthy; 06-24-2014 at 03:34 AM.

  7. #7
    Registered User
    Join Date
    05-16-2014
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: After concatenateing need to get rid of last comma

    Hi pls try this.

    Keep the sheet that you need the comma active and run this code.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,939

    Re: After concatenateing need to get rid of last comma

    =SUBSTITUTE(SUBSTITUTE(LEFT(A1,LEN(A1)-1),",","&",LEN(A1)-LEN(SUBSTITUTE(A1,",",""))-1),", , ",", ")
    try this
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  9. #9
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    Re: After concatenateing need to get rid of last comma

    Quote Originally Posted by FDibbins View Post
    OK use this instead...
    =IFERROR(SUBSTITUTE(LEFT(A2,LEN(A2)-1),","," &",LEN(A2)-LEN(SUBSTITUTE(A2,", "," "))),A2)

    If that still does not work, can you post a sample of when it doesnt work please?
    Hi, I tried the formula but got a error message I will attach part of the worksheet that has the data fields and the formulas and the error message.

    Thanks
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    Re: After concatenateing need to get rid of last comma

    Hi,

    Where there is only 1 data cell it doesn't seem to work I get a message #VALUE!

  11. #11
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    Re: After concatenateing need to get rid of last comma

    Hi,

    I am really not familiar with VBA (if that is what it is).

    Thanks

  12. #12
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    Re: After concatenateing need to get rid of last comma

    Hi AAVINS 73

    I am really not familiar with VBA (if that is what it is).

    Thanks

  13. #13
    Registered User
    Join Date
    06-22-2014
    Location
    brooklyn,ny
    MS-Off Ver
    2010
    Posts
    9

    Re: After concatenateing need to get rid of last comma

    Quote Originally Posted by aavins73 View Post
    Hi pls try this.

    Keep the sheet that you need the comma active and run this code.

    Please Login or Register  to view this content.
    Hi,

    I ran the code and my whole worksheet went haywire.

    Thanks

  14. #14
    Registered User
    Join Date
    05-16-2014
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: After concatenateing need to get rid of last comma

    Hi, It just adds the comma in each cell and removes comma from the last cell as asked by you

  15. #15
    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
    53,048

    Re: After concatenateing need to get rid of last comma

    Thanks for the file

    Your profile indicated 2010, but your sample file indicated 2003 or lower (.xls)

    For 207 and later, use this...
    =IFERROR(SUBSTITUTE(LEFT(L2,LEN(L2)-1),","," &",LEN(L2)-LEN(SUBSTITUTE(L2,", "," "))),LEFT(L2,LEN(L2)-1))

    for 2003 or earlier, use this...
    =IF(ISERROR(SUBSTITUTE(LEFT(L2,LEN(L2)-1),","," &",LEN(L2)-LEN(SUBSTITUTE(L2,", "," ")))),LEFT(L2,LEN(L2)-1),SUBSTITUTE(LEFT(L2,LEN(L2)-1),","," &",LEN(L2)-LEN(SUBSTITUTE(L2,", "," "))))

  16. #16
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,939

    Re: After concatenateing need to get rid of last comma

    =IF((LEN(L2)-LEN(SUBSTITUTE(L2,",","")))=1,LEFT(L2,LEN(L2)-1),SUBSTITUTE(SUBSTITUTE(LEFT(L2,LEN(L2)-1),","," &",LEN(L2)-LEN(SUBSTITUTE(L2,",",""))-1),", , ",", "))
    try this

+ 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. [SOLVED] Finishing an VBA program
    By Nuno Neves in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2014, 11:56 AM
  2. Need Help Finishing My Sheet
    By Adam Schaefer in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-18-2013, 10:02 PM
  3. [SOLVED] I need help with finishing a macro.
    By ATOP in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 11:38 AM
  4. [SOLVED] Loop not finishing
    By boomersooner5136 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-14-2012, 10:51 AM
  5. macro not finishing task
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-29-2007, 07:32 PM

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