Sort a range by occurence using array formula in excel
Question: How do I sort a range containing multiple columns and rows by occurence?
Answer: The range is sorted by occurrence from large to small. See picture below.
Array formula in B9:
=INDEX(tbl, MIN(IF(MAX(COUNTIF(tbl, tbl)*NOT(COUNTIF($B$8:B8, tbl)))=COUNTIF(tbl, tbl), ROW(tbl)-MIN(ROW(tbl))+1, "")), MATCH(MAX(COUNTIF(tbl, tbl)*NOT(COUNTIF($B$8:B8, tbl))), (COUNTIF($B$8:B8, "<>"&INDEX(tbl, MIN(IF(MAX(COUNTIF(tbl, tbl)*(COUNTIF($B$8:B8, "<>"&tbl)-ROWS($B$8:B8)+1))=COUNTIF(tbl, tbl)*(COUNTIF($B$8:B8, "<>"&tbl)-ROWS($B$8:B8)+1), ROW(tbl)-MIN(ROW(tbl))+1, "")), , 1))-ROWS($B$8:B8)+1)*COUNTIF(tbl, INDEX(tbl, MIN(IF(MAX(COUNTIF(tbl, tbl)*(COUNTIF($B$8:B8, "<>"&tbl)-ROWS($B$8:B8)+1))=COUNTIF(tbl, tbl), ROW(tbl)-MIN(ROW(tbl))+1, "")), , 1)), 0)) + CTRL + SHIFT + ENTER copied down as far as necessary.
Named ranges
tbl (B3:E6)
What is named ranges?
Download excel sample file for this tutorial.
Sort a range by occurences.xls
(Excel 97-2003 Workbook *.xls)
Functions in this article:
IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
NOT(logical)
Changes FALSE to TRUE or TRUE to FALSE
MATCH(lookup_value;lookup_array; [match_type]
Returns the relative position of an item in an array that matches a specified value
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition
MIN(number1,[number2])
Returns the smallest number in a set of values. Ignores logical values and text
ROWS(array) returns the number of rows in a reference or an array
MAX(number1,[number2],)
Returns the largest value in a set of values. Ignores logical values and text.
This blog article is one out of thirteen articles on the same subject "unique".
- How to extract a unique distinct list from a column in excel
- Extract a unique distinct list from two columns using excel 2007 array formula
- Extract a unique distinct list from three columns in excel
- Extract distinct unique sorted year and month list from a date series in excel
- Create a unique distinct list from a date range in excel
- Unique values from multiple columns using array formulas
- Extract a unique distinct list sorted from A-Z from range in excel
- Sort a range by occurence using array formula in excel
- Filter unique distinct values from two ranges combined in excel 2007
- Create a unique list and sort by occurrances from large to small
- Unique list to be created from a column where an adjacent column has text cell values
- Create unique list from column where an adjacent column meets criteria
- How to create a unique distinct list where other columns meet two criteria
Related posts:
- Sort a range from A to Z using array formula in excel
- Filter unique rows and sort by date using array formula in excel
- Filter unique values from a range using array formula in excel
- Sort text cells alphabetically from two columns using excel array formula
- Unique distinct values from multiple columns using array formula
- Extract duplicates from a range using excel array formula
- Filter duplicate rows and sort by date using array formula in excel
- Filter duplicates from two columns combined and sort from A to Z using array formula in excel
- Filter values existing in range 1 but not in range 2 using array formula in excel
- Filter unique distinct text values using “begins with” criterion in a range using array formula in excel



August 20th, 2009 at 2:41 pm
Your array formulas are very interesting.
But this fails if there is two or more values whith the same frequency.
Many thanks and best regards
August 20th, 2009 at 9:49 pm
Thanks for your comment! I have changed the formula and the attached excel file. The formula doesn´t work with blank cells.
September 16th, 2009 at 2:49 pm
Hi, very nice formula! I´m trying to do something like this, but I need to show one more column at the side of each unique element with the count of occurrences
September 17th, 2009 at 11:48 am
Fernando,
In the above example, try this formula in C9 copied down as far as necessary.
=COUNTIF(tbl, B9) + CTRL + SHIFT + ENTER