+ Reply to Thread
Results 1 to 14 of 14

formula to create list of unique items

  1. #1
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    formula to create list of unique items

    Thanks for looking.

    I have a column that looks something like (it is VERY long and has over 20 different names):
    abe
    abe
    abe
    abe
    ben
    ben
    ben
    cat
    cat
    john
    john
    john
    john
    tex
    tex

    I want to create another column (automatically) that lists each of of those once:
    abe
    ben
    cat
    john
    tex

    Any idea of how I can do this automatically?

    Thanks.
    Last edited by pink; 02-26-2009 at 01:11 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: I don't know what this would be called...

    Two formulas together will do this, and both are array formulas. Let's assume that list is in column A.

    Over in another column, let's use M, enter this formula in M1:

    =INDEX($A$1:$A$1000,MATCH(0,COUNTIF($A$1:$A$1000,"<"&$A$1:$A$1000),0))
    ...and press CTRL-SHIFT-ENTER to activate an array in that cell, ENTER alone will not work.

    Then in M2 enter this array formula:

    =IF(COUNTIF($A$1:$A$1000,">"&M1),INDEX($A$1:$A$1000,MATCH(COUNTIF($A$1:$A$1000,"<="&M1),COUNTIF($A$1:$A$1000,"<"&$A$1:$A$1000),0)),"")
    ...and press CTRL-SHIFT-ENTER to activate an array in that cell, ENTER alone will not work.

    Now, copy that second formula down as many cells as necessary to get the full list to appear, and maybe some extras for good measure.

    NOTE: Side effect will also be the list created will be alphabetized.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    Re: I don't know what this would be called...

    Quote Originally Posted by JBeaucaire View Post
    Two formulas together will do this, and both are array formulas. Let's assume that list is in column A.

    Over in another column, let's use M, enter this formula in M1:

    =INDEX($A$1:$A$1000,MATCH(0,COUNTIF($A$1:$A$1000,"<"&$A$1:$A$1000),0))
    ...and press CTRL-SHIFT-ENTER to activate an array in that cell, ENTER alone will not work.

    Then in M2 enter this array formula:

    =IF(COUNTIF($A$1:$A$1000,">"&M1),INDEX($A$1:$A$1000,MATCH(COUNTIF($A$1:$A$1000,"<="&M1),COUNTIF($A$1:$A$1000,"<"&$A$1:$A$1000),0)),"")
    ...and press CTRL-SHIFT-ENTER to activate an array in that cell, ENTER alone will not work.

    Now, copy that second formula down as many cells as necessary to get the full list to appear, and maybe some extras for good measure.

    NOTE: Side effect will also be the list created will be alphabetized.
    Perfect, thank you.

    Please edit the title
    Sorry about that.

  4. #4
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    re: formula to create list of unique items

    I'm bumping this up not because the previous solution didn't work, but because I'm trying to see if there is any other way of doing this that won't bog down the system as much.

    Does anybody know of any other method?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    re: formula to create list of unique items

    You want a macro running in the background all the time? Every time you make a change to the sheet, or just to the "names" column, we could make the macro recreate a unique names list for you.

    Pro - it's almost instantaneous, no array formulas so no autocalc going on all the time.

    Con - you would lose the Edit > Undo option on the menus. Side effect of using a Worksheet_Change macro going all the time.

    Let me know. If this is OK, please identify the actual column that will have the names, and the actual column you would like the name to appear in, starting at what cell. Perhaps even upload a sample file so it's absolutely clear your required results.

  6. #6
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    Re: "formula to create a list of unquie items"

    Thanks for your help. I really appreciate it.

    I do not think having a script running continuously in the background would be a good idea either, mainly the data source in this particular spreadsheet isn't updated individually.

    In my spreadsheet, the user runs a macro to retrieve his/her account data from a website. This may include data on 2 days, it may have data on 30 days. Nothing is manually inputted.

    What I'm trying to do with this is to provide some analysis on each individual date on this data... and by grabbing a "unique date list," I can use some other functions to match / analyze.

    I understand that the way you mentioned earlier may already be the fastest way; I'm just making sure

    Again, thakns for your help.. and I hope I'm clear in my description of the data.

    Thanks.

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: formula to create list of unique items

    There are a number of ways that are not so "automatic" that can be done quickly and won't drain your system. Two that come to mind are the Advanced Filter or a dummy column that detects duplicates that you can then sort on.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

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

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formula to create list of unique items

    An "on-demand" macro to create a list of unique dates from the column in question would not be resource intense. Having it run in the background wouldn't either. It doesn't sound like it's a lot of data (is it?), but this is doable many ways, including the way you've already got. Up to you if this is solved or not.

  9. #9
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    Re: formula to create list of unique items

    Quote Originally Posted by ChemistB View Post
    There are a number of ways that are not so "automatic" that can be done quickly and won't drain your system. Two that come to mind are the Advanced Filter or a dummy column that detects duplicates that you can then sort on.
    Hmm, I like the dummy variable idea. I'll try it soon, and I'll post if it works.

    An "on-demand" macro to create a list of unique dates from the column in question would not be resource intense. Having it run in the background wouldn't either. It doesn't sound like it's a lot of data (is it?), but this is doable many ways, including the way you've already got. Up to you if this is solved or not.
    Its actually quite a lot of data- Most data sets are about 1000 rows, maybe 5-6 columns?

    Thank you both again for your help. I'll post back shortly.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formula to create list of unique items

    The array I suggested above does it, but if you want a non-array solution, attached is an example of how something like that could work.

    A helper column indicates the first instance of each unique name and supplies a unique "index number" for each name it flags. Colored in yellow.

    The pink cells are the final list. A standard index/match formula finds the name associated with each index number. No array at all.
    Attached Files Attached Files
    Last edited by JBeaucaire; 02-24-2009 at 09:55 PM. Reason: Took out second helper column, used row()-1 flag in results formula instead.

  11. #11
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    Re: formula to create list of unique items

    Quote Originally Posted by JBeaucaire View Post
    The array I suggested above does it, but if you want a non-array solution, attached is an example of how something like that could work.

    A helper column indicates the first instance of each unique name and supplies a unique "index number" for each name it flags. Colored in yellow.

    The pink cells are the final list. A standard index/match formula finds the name associated with each index number. No array at all.
    Whoa, its beautiful

    I've just figured the COUNTIF out, and working through the index/match... but it looks like this will run a lot quicker.

    I'll post an update once I decipher the formulas and input it in my my xls.

    Thank you.

  12. #12
    Registered User
    Join Date
    08-09-2004
    Posts
    14

    Talking Re: formula to create list of unique items


    This will actually delete rows that are duplicates leaving you only with the unique names.

    I just copied and pasted it from my utility. You can get the whole thing from -

    http://www.geocities.com/excelmarksw...Duplicates.xls


    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 11-08-2012 at 02:13 PM.

  13. #13
    Registered User
    Join Date
    02-09-2007
    Posts
    39

    Re: formula to create list of unique items

    Quote Originally Posted by JBeaucaire View Post
    The array I suggested above does it, but if you want a non-array solution, attached is an example of how something like that could work.

    A helper column indicates the first instance of each unique name and supplies a unique "index number" for each name it flags. Colored in yellow.

    The pink cells are the final list. A standard index/match formula finds the name associated with each index number. No array at all.
    I didn't forget about this thread

    I got everything to work, and yes, this method is a lot faster than the array method.

    JBeaucaire-- you offered 3 solutions for me here. Thank you.

  14. #14
    Registered User
    Join Date
    12-13-2014
    Location
    Ulaanbaatar, Mongolia
    MS-Off Ver
    2013
    Posts
    1

    Re: I don't know what this would be called...

    Perfect.... It worked.

    Quote Originally Posted by JBeaucaire View Post
    Two formulas together will do this, and both are array formulas. Let's assume that list is in column A.

    Over in another column, let's use M, enter this formula in M1:

    =INDEX($A$1:$A$1000,MATCH(0,COUNTIF($A$1:$A$1000,"<"&$A$1:$A$1000),0))
    ...and press CTRL-SHIFT-ENTER to activate an array in that cell, ENTER alone will not work.

    Then in M2 enter this array formula:

    =IF(COUNTIF($A$1:$A$1000,">"&M1),INDEX($A$1:$A$1000,MATCH(COUNTIF($A$1:$A$1000,"<="&M1),COUNTIF($A$1:$A$1000,"<"&$A$1:$A$1000),0)),"")
    ...and press CTRL-SHIFT-ENTER to activate an array in that cell, ENTER alone will not work.

    Now, copy that second formula down as many cells as necessary to get the full list to appear, and maybe some extras for good measure.

    NOTE: Side effect will also be the list created will be alphabetized.

+ 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