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.

range-sorted-by-occurence

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.

Recommended articles

Create a unique distinct list and sort by occurrances from large to small

Question: How do I create a new unique distinct list from a column. I also want the list sorted from large […]

How to count unique distinct occurrences for each date in excel

Question: How to count unique distinct values on the same date? Answer: Array formula in D3: =SUM(--(FREQUENCY(IF(B3=Date, COUNTIF(Item, "<"&Item), ""), […]

Count text that occurs multiple times in excel cell

Question: How do I count how many times a text string occurs in a cell in excel? Answer: Formula in […]

Count occurences of a specific text string in a column in excel

Question: How do I count the number of times a text string exists in a column? Answer: Array formula in […]

Unique distinct list sorted based on occurrance in a column in excel

Question: How do I create a unique distinct list from a column, sorted by occurance? Answer: Array formula in A17: […]

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.