Sorting a list based on number of times a word appears in a list

Copper Contributor

Hi,

 

I have a list containing specific words (all repeated at various times).  I know how to sort alphabetically, but I then need them sorted and grouped by the number of times each word appears in the list.  For example:

 

Original list:

banana

orange

cherry

lime

lime 

orange

banana

banana

banana

orange

 

The sorted list should look like the following:

banana

banana

banana

banana

banana (in original list 5 times, so shows up 1st or last)

orange 

orange

orange (shows up in original list 3 times)

lime (shows up in original list 2 times)

lime

cherry (only shows up once)

 

Or the list could be reversed, with "cherry" first and "banana" last, based on the number of times the word shows up in the list.  

 

The list can be either ascending or descending, it does not matter - just so long as it "groups" the words in the list by the number of times it shows up once the list is sorted alphabetically.  I can't figure a formula given those parameters.  Using Office 2019 in Windows 10 Pro.

 

Thanks!

5 Replies

@DebbieLM 

I'd use a helper column. The formula in B1 is =COUNTIF($A$1:$A$10,A1) and this has been filled down.

S0051.png

Sort on column B, largest to smallest:

S0052.png

@DebbieLM 

Because Excel 365 is intrinsically array based, the formula

= SORTBY(Fruit, COUNTIFS(Fruit, Fruit), -1) 

works without helper ranges or manual sorting.

image.png

@Hans Vogelaar 

 

Thank you - I think that will do the trick!

And another possibility - thank you!