+ Reply to Thread
Results 1 to 4 of 4

Replace duplicate codes in string in a single cell

  1. #1
    Registered User
    Join Date
    05-29-2019
    Location
    UK
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Replace duplicate codes in string in a single cell

    Hi guys,

    New to this forum as I have a problem I can't solve. I have a worksheet comprising a single column that has data in it comprising codes separated by commas. The codes might be repeated and need to be replaced if they repeat with the number of times they repeat.

    Below is a potential entry:

    aa,bb,aa,cc,dd,aa

    I need to replace this entry with:

    aa*3,bb,cc,dd

    Because the code aa appears 3 times.

    Another example might be: aa,aa,bb,bb,cc,cc,aa which would need to result in aa*3,bb*2,cc*2

    Now, for each entry in the worksheet I won't know which codes repeat in a given cell or how many times they repeat and they are not guaranteed to be in the same order. So, for example:

    aa,aa,bb,cc,aa,dd would also need to be transposed to aa*3,bb,cc,dd

    The codes aa,bb,cc etc are all alphanumeric and the same length.

    I'm struggling so any help gratefully accepted.

    Regards.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Replace duplicate codes in string in a single cell

    You could use Power Query - something like:

    Please Login or Register  to view this content.
    Worked example file: https://excel.solutions/xlf_1277667/
    Last edited by Olly; 05-29-2019 at 05:46 AM.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    05-29-2019
    Location
    UK
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Re: Replace duplicate codes in string in a single cell

    That's brilliant - many thanks.

    D.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    82,848

    Re: Replace duplicate codes in string in a single cell

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Replies: 2
    Last Post: 06-04-2015, 12:47 PM
  2. Replies: 0
    Last Post: 10-09-2013, 07:59 PM
  3. [SOLVED] Replace duplicate words in string of text
    By financegrl in forum Excel General
    Replies: 6
    Last Post: 09-24-2012, 05:06 PM
  4. Replies: 1
    Last Post: 01-26-2012, 10:06 AM
  5. Replies: 2
    Last Post: 06-01-2011, 09:45 AM
  6. Remove duplicate from single string
    By cc9083 in forum Excel General
    Replies: 5
    Last Post: 05-23-2009, 05:53 AM
  7. A Macro to replace a string in a cell with a string from another cell???
    By Plica05 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2005, 04:23 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