+ Reply to Thread
Results 1 to 9 of 9

is it possible to scan a string and eliminate multiple instances of a word?

  1. #1
    Registered User
    Join Date
    12-12-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    8

    is it possible to scan a string and eliminate multiple instances of a word?

    Hello all!

    How are you all doing today?

    I imagine you guys have answered many, many posts on here, however I don't think you've ever run into this kind of situation! I'd like excel to take a string containing a list with commas in between, from a single cell, which may look like this:

    "item 1, item 2, item 4, item 1, item 3, item 1, item 4" (the items will not actually say "item" - they have different names)

    I'd like excel to eliminate multiple instances of the same item from between the commas and then post them all in one column in a range, one item per cell.

    So that would be like this
    _ | <--A-->|<--B-->|
    1 | item 1 |
    2 | item 2 |
    3 | item 4 |
    4 | item 3 |
    5 |

    I tried showing a visual representation of it


    Thank you for your input!

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    Hi
    You can use "Text to Columns" and then copy with transposition. To get rid of duplicates use advance filter
    If You want do this with VBA you can record this and try to adjust
    Last edited by tom1977; 12-12-2011 at 10:53 AM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    Better if the visual representation were a sample workbook with some typical data.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    12-12-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    I've uploaded the excel file with a sample string. Hope this helps!
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-12-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    I never worked with recording what I am doing and it might seem a bit unclear to excel since it doesn't know I'm ignoring multiple instances of the same word when I copy them to a range. Also there will be lots of those strings, each with different items in it and so doing advanced filter would mean I have to do that for each string no?

  6. #6
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    In your example you eliminated a part of the string from the result. On what basis should that happen in the future?

  7. #7
    Registered User
    Join Date
    12-12-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    Yes, if a substring appears more than once it should be deleted when entering all the items in the range format.

    I was thinking if we have a function that finds the first word in a string then searches the string for more of those same sub strings and deletes them, then goes to the second word and searches it etc. then the new string is entered as a range in a column.

    OR

    If we copy the original string in a range in a column and THEN we search for multiples of the same substring and delete them.

    I'm not sure which of these ways it's easier or if there is another method? I can't seem to put together a function that can do all this.

  8. #8
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    my proposition with vba only ex>2007

    Please Login or Register  to view this content.
    Last edited by tom1977; 12-12-2011 at 06:15 PM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: is it possible to scan a string and eliminate multiple instances of a word?

    Slight variation, based on Tom's solution:

    Please Login or Register  to view this content.

    In this approach, the Trim loop is done in the array and then the array transposed onto the sheet.

    Regards, TMS

+ 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