+ Reply to Thread
Results 1 to 17 of 17

Extract unique strings from excel cells across rows and columns

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Extract unique strings from excel cells across rows and columns

    I need to extract unique strings from excel cells.
    I have a spreadsheet with 2 columns each cell in the column contains a long text string.
    That long text string is composed of several strings i need to extract. each individual string is of variable lenght but there is always a pattern for example:
    apple: pineapple: tomatoe: carrot:
    apple: carrot: potatoe:
    pear: apple: lettuce: pepper: fish: brocolli:
    Each cell's string can contain one or 100 repetitions of the pattern.
    each row (and there can be up to 600000 rows) will contain various strings but there will be some repetition.

    My goal is to parse the cells and come up with a unique list of strings:
    apple, carrot, tomatoe, pineapple, potatoe, pear, lettuce, pepper, fish, brocolli.

    I'm thinking i'll need some sort of macro to accomplish this but i have no idea where to startWhat i'm doing manually right now is copy the first unique string i see to a separate workbook, then run a replace all with blank to get rid of all other instances of the string until eventually I have a list of uniques in a separate spreadsheet and no strings in my source
    Attached Files Attached Files
    Last edited by quedan; 01-28-2013 at 02:17 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Extract unique strings from excel cells across rows and columns

    This might be easier to solve if you post your spreadsheet with only a sample of data. For that sample, also give us the expected results
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extract unique strings from excel cells across rows and columns

    added sample file to top post.

  4. #4
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extract unique strings from excel cells across rows and columns

    is this possible?

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Extract unique strings from excel cells across rows and columns

    I dont see any file?

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extract unique strings from excel cells across rows and columns

    i had uploaded the file but not linked it to the post its there now.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extract unique strings from excel cells across rows and columns

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by AB33; 01-26-2013 at 05:48 PM.

  8. #8
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extract unique strings from excel cells across rows and columns

    This works like a charm.
    Not knowing anything about VB script can this be modified to work off the currently active sheet rather then the one named one?
    also can it be modified to process both column A and column B? its ok if it does one after the other. and then dumps the results in columns A and B respectively on the Results sheet.
    I was thinking of something like this but i'm getting subscript out of range errors on line 10
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extract unique strings from excel cells across rows and columns

    quedan,
    Please do not reply with quote, it has not purpose, but clutters the space. Just press reply. It is difficult to know which is line10. My code works on the attached sheet. You had "Source" and Results sheets. Could you please attach your worksheet so as to see where the error is and you also said, I missed column B which I did not see. So, when you attach the error you are getting, could also inlcude what is missing and the desired result. I will have a look tomorrow-(dose off for now )and will get back to you at some point tomorrow.

  10. #10
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extract unique strings from excel cells across rows and columns

    I didnt reply with quote added some of my badly written code which you can feel free to ignore
    I figured out the issue with the error it was a typo in my worksheet name.

    See attached an updated sample, it has unique strings in both columns A and B. along with two results i'm hoping to get one ideal and one sufficient.
    I tried creating a macro that would pull data only from column B (in the excel file) and list it on the results sheet in column B but it does not appear to do anything.
    Attached Files Attached Files

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Extract unique strings from excel cells across rows and columns

    @ AB33 quedan did not "reply with quote". He posted a segment of his own code, and was asking questions about it

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Extract unique strings from excel cells across rows and columns

    Do you mean like this?
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 01-25-2013 at 07:57 PM.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extract unique strings from excel cells across rows and columns

    quedan,Fdibbins

    Sorry for Quote,I was misread your reply. I just do not like Quote

    I have now ameded my code # 7 above and seem to get your ideal solution. I have two codes, one is attached with the macro, but you may not want to clear the signs from the source book, so the code you see on this page does not clear the signs from the source book. Try the this code with your sample.
    Last edited by AB33; 01-27-2013 at 09:38 AM.

  14. #14
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Extract unique strings from excel cells across rows and columns

    Hi, AB33,

    you might like to take a look at the Forum Rules, especially Rule #6a Feedback:
    Never edit a thread or post to which others have already responded
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extract unique strings from excel cells across rows and columns

    Holger,

    I have lost you!

    I have amended my own code. I see people do this, even Arlu, one of the moderators, does it quite often.

  16. #16
    Registered User
    Join Date
    01-25-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Extract unique strings from excel cells across rows and columns

    Thanks guys.
    Jindon's solution is the easiest for me to use.
    AB33 the changed solution is having issues when dealing with two columns it splits the text in each cell but then dumps it for each individual cell instead of just selecting the uniques. No matter though it works great with a single column in cases where Jindon's solution has issues due to the number of lines to be processed.

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extract unique strings from excel cells across rows and columns

    Quedan,
    Yes , Jindon's code is short and simple.
    I thought your ideal solution is to merge column A and B and then list only unique values from both columns and this is exactly what my code does.

+ 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