The Computer Oracle

How do I get the distinct/unique values in a column in Excel?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: City Beneath the Waves Looping

--

Chapters
00:00 Question
00:31 Accepted answer (Score 361)
01:01 Answer 2 (Score 139)
01:59 Answer 3 (Score 27)
02:21 Answer 4 (Score 25)
03:37 Thank you

--

Full question
https://superuser.com/questions/49614/ho...

Answer 3 links:
[suggested by Nathan DeWitt]: https://superuser.com/a/49618/151054

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#microsoftexcel

#avk47



ACCEPTED ANSWER

Score 377


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




ANSWER 2

Score 140


Excel 2007 and 2010:
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.




ANSWER 3

Score 29


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).




ANSWER 4

Score 6


Or you can include the filter option in a macro

    Columns("A:A").AdvancedFilter Action:=xlFilterInPlace, Unique:=True