If I have a column with values, and I want to find out what distinct values are in there (not how many - but the actual distinct values), how can I do that?

In SQL Server I would do something like

SELECT Distinct(MyColumn) FROM MyTable.
link|improve this question

1  
need to know what version of excel you're using... – Nathan DeWitt Oct 1 '09 at 16:00
feedback

4 Answers

up vote 34 down vote accepted

Excel 2007:
Use the Remove Duplicates menu option under the Data header.

Excel 2003:
Easy way:

  1. Make sure your data has a header
  2. Data --> Filter --> Advanced Filter
  3. Check Unique Records Only
  4. Select Copy to another location
  5. Click OK

Hard way:

Write a macro with the following code:

'Remove duplicates from sorted list
Sub getDistinct()
    Do While ActiveCell.Value <> ""
        If ActiveCell.Value = ActiveCell.Offset(1, 0).Value Then
            ActiveCell.Select
            Selection.Delete Shift:=xlUp
        Else
            ActiveCell.Offset(1, 0).Activate
        End If
    Loop
End Sub

That gives you your distinct list. You may want to copy your list to another sheet first.

link|improve this answer
5  
Thanks! This is a proof that Stack Exchange is way better than any other source for technical information. All other google results are useless, and unranked. Also I wonder how experts-exchange survive – Ehrann Mehdan Mar 23 '11 at 2:53
feedback

Simpler than you might think:

  • Click the Data Ribbon Menu
  • Select the Advanced Button in the Sort & Filter section
  • Fill in the dialog Box, copying the results to another location and making sure you tick Unique records only

enter image description here

link|improve this answer
7  
For those of us still living a ribbon-free existence, it's Data->Filter->Advanced. – Boofus McGoofus Oct 1 '09 at 16:39
feedback

Or you can include the filter option in a macro

    Columns("A:A").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
link|improve this answer
feedback

Or (a simple crude way):

In B1,

=IF(COUNTIF(A$1:A1,A1)=1,A1,"") 

and copy down. It just copies the first occurrence of each value across (in the row that it occurs in).

link|improve this answer
feedback

protected by studiohack Aug 16 '11 at 15:40

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.