+ Reply to Thread
Results 1 to 10 of 10

Help with Formula: Remove trailing commas or using IF to remove results from blank cells?

  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    Florida, USA
    MS-Off Ver
    Excel 2008 (Mac)
    Posts
    4

    Question Help with Formula: Remove trailing commas or using IF to remove results from blank cells?

    I am using a formula to pull results from multiple cells and concatenate them, place a comma between, each entry, and remove extra spaces so I can import the csv into a database.
    Basically, I am trying to take text entries from multiple columns and put them together with comma separators.
    So if...
    Column AZ2=Visa
    Column BA2=Mastercard
    Column BB2=Amex
    Column BC2=Discover
    Results = Visa,Mastercard,Amex,Discover

    I am using the following formula:

    =SUBSTITUTE(TRIM(AZ2&","&BA2&","&BB2&","&BC2),",,",",")

    This works fine EXCEPT that if the last field, or all fields, are blank the formula renders the comma anyway.

    So lets say that BB2 and BC2 is empty.
    Instead of..
    Visa,Mastercard I get Visa,Mastercard,
    ..and that trailing comma is keeping the records from importing.
    Additionally, if all fields are empty instead of an empty result I get ,,

    Is there something I can do to fix this formula or can I use IF to skip blank cells? (I'm lost on the syntax)

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    Hi and welcome to the forum,

    Try this formula

    =SUBSTITUTE(TRIM(CONCATENATE(AZ2&" ",BA2&" ",BB2&" "&BC2))," ",", ")
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Registered User
    Join Date
    01-09-2014
    Location
    Florida, USA
    MS-Off Ver
    Excel 2008 (Mac)
    Posts
    4

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    Awesome! Worked like a charm. Thanks!

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    You're welcome. Don't forget to thank those who helped by clicking on Add Reputation * and please mark thread as "Solved" if your issue has been resolved. (Selecting Thread Tools-> Mark thread as Solved).

  5. #5
    Registered User
    Join Date
    01-09-2014
    Location
    Florida, USA
    MS-Off Ver
    Excel 2008 (Mac)
    Posts
    4

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    One small problem…

    It is also replacing spaces between words in the same cell with commas>
    American Express becomes American,Express

    I just shortened it to AmEx for now but am looking for a better solution.

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    Then try this

    =SUBSTITUTE((SUBSTITUTE(TRIM(CONCATENATE(AZ2&" ",BA2&" ",BB2&" "&BC2))," ",", ")),"American, Express","American Express")

  7. #7
    Registered User
    Join Date
    01-09-2014
    Location
    Florida, USA
    MS-Off Ver
    Excel 2008 (Mac)
    Posts
    4

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    Quote Originally Posted by AlKey View Post
    Then try this

    =SUBSTITUTE((SUBSTITUTE(TRIM(CONCATENATE(AZ2&" ",BA2&" ",BB2&" "&BC2))," ",", ")),"American, Express","American Express")
    That did the trick. Thanks!

  8. #8
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    Thanks for the feedback!

  9. #9
    Registered User
    Join Date
    05-26-2016
    Location
    California
    MS-Off Ver
    Office 2010
    Posts
    1

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    I'm also having a similar issue with the formula replacing spaces between words in the same cell but I have many different occurrences so I cannot simply do the substitution at end of the formula as you did for American,Express and American Express... Any ideas? Thx

  10. #10
    Registered User
    Join Date
    11-23-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    1

    Re: Help with Formula: Remove trailing commas or using IF to remove results from blank cel

    Hi

    This solution was very useful!

    However, is there a way to change the formula so that there is an "&" sign visible in the cell before the last entry?

    So in the example below, where BB2 and BC2 are blank, the results would be Visa, Mastercard & Amex

    Column AZ2=Visa
    Column BA2=Mastercard
    Column BB2=Amex
    Column BC2=
    Results = Visa, Mastercard & Amex

+ 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. Formula To Remove Blank Cells
    By King_Quake in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 02-04-2014, 12:59 AM
  2. Concatenate cell Title and remove trailing commas using Excel VB
    By missit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2013, 12:36 AM
  3. Replies: 5
    Last Post: 11-26-2012, 08:44 AM
  4. Macro, to remove commas and remove speach marks
    By 5h1l in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2012, 12:06 PM
  5. remove guotes from cells containing commas
    By hwalders in forum Excel General
    Replies: 1
    Last Post: 09-20-2005, 11:05 AM

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