Do you know a way in Excel to "calculate" by formula a list of unique values ?
E.g: a range contains values "red"
, "blue"
, "red"
, "green"
, "blue"
, "black"
and I want to have as result "red
, "blue"
, "green"
, "black"
+ eventually 2 other blank cells.
I already found a way to get a calculated sorted list using SMALL or LARGE combined with INDEX, but I'd like to have this calculated sort as well, WITHOUT USING VBA.
Solution
I created a function in VBA for you, so you can do this now in an easy way.
Create a VBA code module (macro) as you can see in this tutorial.
Module
inInsert
.Excel Macro-Enabled
inSave As
.Source code
Usage
Just enter
=listUnique(range)
to a cell. The only parameter isrange
that is an ordinary Excel range. For example:A$1:A$28
orH$8:H$30
.Conditions
range
must be a column.range
starts.Example
Regular case
Empty cell case
It works in columns that have empty cells in them. Also the function outputs nothing (not errors) if you overwind the cells (calling the function) into places where should be no output, as I did it in the previous example's "2. Grow it" part.
Resorting to a PivotTable might not count as using formulas only but seems more practical that most other suggestions so far:
Assuming Column A contains the values you want to find single unique instance of, and has a Heading row I used the following formula. If you wanted it to scale with an unpredictable number of rows, you could replace A772 (where my data ended) with =ADDRESS(COUNTA(A:A),1).
=IF(COUNTIF(A5:$A$772,A5)=1,A5,"")
This will display the unique value at the LAST instance of each value in the column and doesn't assume any sorting. It takes advantage of the lack of absolutes to essentially have a decreasing "sliding window" of data to count. When the countif in the reduced window is equal to 1, then that row is the last instance of that value in the column.
This is an oldie, and there are a few solutions out there, but I came up with a shorter and simpler formula than any other I encountered, and it might be useful to anyone passing by.
I have named the colors list
Colors
(A2:A7), and the array formula put in cell C2 is this (fixed):Use
Ctrl+Shift+Enter
to enter the formula in C2, and copy C2 down to C3:C7.Explanation with sample data {"red"; "blue"; "red"; "green"; "blue"; "black"}:
COUNTIF(Colors,"<"&Colors)
returns an array (#1) with the count of values that are smaller then each item in the data {4;1;4;3;1;0} (black=0 items smaller, blue=1 item, red=4 items). This can be translated to a sort value for each item.COUNTIF(C$1:C...,Colors)
returns an array (#2) with 1 for each data item that is already in the sorted result. In C2 it returns {0;0;0;0;0;0} and in C3 {0;0;0;0;0;1} because "black" is first in the sort and last in the data. In C4 {0;1;0;0;1;1} it indicates "black" and all the occurrences of "blue" are already present.SUM
returns the k-th sort value, by counting all the smaller values occurrences that are already present (sum of array #2).MATCH
finds the first index of the k-th sort value (index in array #1).IFERROR
is only to hide the#N/A
error in the bottom cells, when the sorted unique list is complete.To know how many unique items you have you can use this regular formula:
Select the column with duplicate values then go to Data Tab, Then Data Tools select remove duplicate select 1) "Continue with the current selection" 2) Click on Remove duplicate.... button 3) Click "Select All" button 4) Click OK
now you get the unique value list.
You can also do it this way.
Create the following named ranges:
With these 3 named ranges you can generate the ordered list of unique values with the formula below. It will be sorted in ascending order.
You will need to substitute the row number of the cell just above the first element of your unique ordered list for the '?' character.
eg. If your unique ordered list begins in cell B5 then the formula will be: