+ Reply to Thread
Results 1 to 4 of 4

Sorting to find unique entries

Hybrid View

  1. #1
    Registered User
    Join Date
    11-07-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    2

    Sorting to find unique entries

    Hi, I'm fairly new to VBA and programming in general and I've been presented with a task that has thrown me for a loop. I know it's not really a hard task but for some reason I can't grasp how I should do it. My question involves lots of data that is going to be changing on a weekly basis lets say in column A I have data

    A
    A
    A
    A
    A
    A
    A
    B
    B
    B
    B
    B
    C
    C
    C
    C

    and I want to sort through this data and only find the "unique" data entries. ie. I only want A, B, C so that I can use them in a combo box for drop down selection. Right now I have it so that the drop down box is showing all the A's, B's, C's, etc. I know this can be done with some sort of sorting algorithm but I'm severely confused. Could anyone help me out?
    Last edited by Bahester; 11-07-2010 at 10:13 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: Question I can't figure out

    You can use a second column to collect the unique values, then use that second column for your drop down.

    Assuming column A has the original values, put this array formula in B1:

    =INDEX(A$1:A$100,MATCH(0,COUNTIF(A$1:A$100,"<"&A$1:A$100),0))

    ...confirm by pressing CTRL-SHIFT-ENTER to activate the array. The first value should appear.

    Then in B2, put this different array formula, also with ctrl-shift-enter:

    =IF(COUNTIF(A$1:A$100,">" & B1), INDEX(A$1:A$100, MATCH(COUNTIF(A$1:A$100,"<=" & B1), COUNTIF(A$1:A$100,"<"&A$1:A$100),0)),"")

    ...and then copy that cell down as far as needed to get the rest of the values to appear.

    Then use this column for your drop down.

    CAVEATS:

    Your data does not have to be sorted as you showed in your example, you'll still get an alphabetical listing.
    Your data can't have any blanks in the range anywhere.
    _________________
    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
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Sorting to find unique entries

    A macro approach to get sheet1 uniques to sheet2:
    Sub CopyUniques()
        Sheets("Sheet2").Columns(1).Clear
        Sheets("Sheet1").Range("A:A").AdvancedFilter Action:=xlFilterCopy, _
            CopyToRange:=Range("AA1"), Unique:=True
        Range("AA2", Range("AA" & Rows.Count).End(xlUp)).Copy Sheets("Sheet2").Range("A1")
        Sheets("Sheet1").Columns(27).Clear
    End Sub

  4. #4
    Registered User
    Join Date
    11-07-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Question I can't figure out

    Sorry, guess I should have been a little more specific. I have a ton of data (it's a big sheet of all types of data) so I can't really do it in the column beside it. I'd like to do it within VBA and preferably I'd like to copy the unique values to a new worksheet and use that for my combo box on my user form.

+ 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