+ Reply to Thread
Results 1 to 14 of 14

Remove duplicate characters from a text string in a cell

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    md
    MS-Off Ver
    Excel 2010
    Posts
    37

    Remove duplicate characters from a text string in a cell

    I have an excel spread-sheet with following data. I need help in reducing the ";" down to 1. if there is only 1 semi colon then leave it as is.
    It appears simple but i am just not able to solve it.
    Any help will be greatly appreciated.

    2120;;;;;;;;;;;;
    ;;;;idea;22045;;;;;;;
    ;;;;xxxxx;00000;;;;;;;detail


    Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Remove duplicate characters from a text string in a cell

    Hi sam99,

    Do a FIND and REPLACE (ctrl-H)...

    Find what ;;
    Replace with ;

    Replace All until all duplicates are gone...

    re-post: highlight your range just in case you don't want others to change

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    md
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Remove duplicate characters from a text string in a cell

    Thanks. It Work. Can we do the same thing using a formula?

  4. #4
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Remove duplicate characters from a text string in a cell

    I tried using a formula, but you'd have to have to use the formula several times...
    =SUBSTITUTE(C1,";;",";")
    then copy this several times across to all to itself...

    It was not very elegant, that's why I simply tried the find and replace...

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

    Re: Remove duplicate characters from a text string in a cell

    Formula version:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

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

  6. #6
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Remove duplicate characters from a text string in a cell

    Almost, tigeravatar, from my understanding, sam99 wants to keep 1 semicolons where there are repeated semicolons... then again, I can be mistaken...

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

    Re: Remove duplicate characters from a text string in a cell

    If that's the case...
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Remove duplicate characters from a text string in a cell

    That's it... awesome formula, tigeravatar!

  9. #9
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Remove duplicate characters from a text string in a cell

    Great job, tiger.

    The only thing I can add to this is this: Why are you (Sam99) ending up with strings in cells with lots of semi-colons? I am assuming you must be using a formula or VBA to concatenate a bunch of other data. If that is the case, then you might consider altering your original code/formula that produces those strings so that it only adds a semi-colon if it finds data to concatenate. That way, you don't need to worry about a formula that removes the extras.

    - Moo

  10. #10
    Registered User
    Join Date
    07-03-2012
    Location
    md
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Remove duplicate characters from a text string in a cell

    First of all Thanks to djapigo and tigeravatar for helping me out with a formula. The first formula that tigeravatar provided is what i was looking for.

    Moo - The reason why we end up with a lot of semicolon is concatenating 22 cell. I do not know vba. writing a formula to concatenate and trim blanks for 22 cells appeared messy to me.

    Sorry about getting back so late.
    Thanks
    Sam

  11. #11
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Remove duplicate characters from a text string in a cell

    Here is a function that you could use to concatenate a range of cells (vertically or horizontally) with semi-colons that will produce clean results (i.e. only semi-colons between found values within the range):
    Please Login or Register  to view this content.
    You can place that in a VBA Module by doing this:
    1. Open your workbook and press Alt+F11
    2. Select Insert >> Module
    3. Paste the above code into that module
    4. Save your worksheet as a Macro-Enabled Worksheet (.xlsm)
    5. Close out the Excel VBA window

    Now, in that workbook, whenever you need to concatenate a range of cells using a semi-colon as a delimiter, use the function 'ConcatRange' like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    or
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    It skips blank cells, so if you have a range of 22 cells that you need to concatenate, it will only return the cells with values in them, separated by semi-colons.

    Hope this helps!

    - Moo

  12. #12
    Registered User
    Join Date
    07-03-2012
    Location
    md
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Remove duplicate characters from a text string in a cell

    Amazing Stuff.. Thanks a lot Moo.

  13. #13
    Registered User
    Join Date
    12-06-2015
    Location
    Cape Town
    MS-Off Ver
    2007
    Posts
    1

    Re: Remove duplicate characters from a text string in a cell

    Hi Tiger
    Your original formula was what I searched for for many hours and couldn't find. I got to this site at 3 in the morning and registered to see your solution but somehow could not. Continued searching the next day and at the point that I gave up I just happened to log back on and would you believe it - I see your formula - so simple so brilliant. It was exactly what I wanted. I did not read further. I implemented your solution - I have "/" in between and viola!! all done. I then decide to read the rest of the thread only to find a beautiful function by Moo - you are THE DOG!

    Thanks Guys
    Raymond
    PS: Imagine what you posted 3 years ago helped me today.
    Last edited by raymonde; 12-07-2015 at 06:45 PM.

  14. #14
    Registered User
    Join Date
    09-22-2020
    Location
    Oregon, USA
    MS-Off Ver
    2019
    Posts
    1

    Smile Re: Remove duplicate characters from a text string in a cell

    Moo - Eight years later - THANK YOU! I was already up to a couple hours and eight helper columns trying to noodle through a workaround because I couldn't find any combination of formulas to do what I needed. This ConcatRange function is brilliant. Thank you for sharing.

+ 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