+ Reply to Thread
Results 1 to 8 of 8

can't remove commas at the end of a string

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    can't remove commas at the end of a string

    In an Excel column I have strings of text. Some end with a comma. Others end without a comma. I want to remove all the commas at the end of the strings. How do I do that? Below is an example.

    Column A
    large building
    small building,
    skyscraper,
    tall, house
    house boat
    cabin

    Note: the comma after "tall" I don't want to remove.
    Last edited by dschmitt; 02-26-2013 at 03:45 AM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: can't remove commas at the end of a string

    Insert column B and into it put the formula:

    =LEFT(A1,LEN(A1)-(RIGHT(A1,1)=","))

    Copy down, then copy the column, paste special|values over the data in column A and then delete column B

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't remove commas at the end of a string

    very strange. If I type a string with a comma at the end into A1 and use your command in B1 it works. However, if I use the command in my data it doesn't work. What could the problem be?

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: can't remove commas at the end of a string

    Could your data have trailing spaces after the comma, perhaps?

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't remove commas at the end of a string

    yes, that was the problem. With TRIM I was able to remove the trailing spaces. Thank you very much for the very speedy help.
    Problem solved.

  6. #6
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't remove commas at the end of a string

    Andrew, one more question.
    I tried to build your command into a small script, but I failed. What did I do wrong here.

    Cells(x, 1).Value = Left(Cells(x, 1), Len(Cells(x, 1)) - (Right(Cells(x, 1), 1) = ",")).Value
    Last edited by dschmitt; 02-26-2013 at 04:26 AM.

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: can't remove commas at the end of a string

    You don't need the .Value on the end.

    Also, because worksheet functions return a value of 1 for a true statement, while VBA uses a value of -1 you have to change the last minus to a plus:

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: can't remove commas at the end of a string

    I see. I understand. I tested it. It works.
    Thank you very much again.

+ 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