The formula didn't work as expected as the method is for input with no duplicates.
Getting a sorted list of unique items is easy in Excel for Microsoft 365: =SORT(UNIQUE(TOCOL(_0_unsorted_input,1)))
Since these functions are not available in Excel 2016, a few interim steps are required. Here's one way to do it:
Removing blanks as second steps could work, but it requires manually selecting interim range - so I have chosen this order.
Used Name Manager
Defining names for ranges and formulas makes it easy to follow and troubleshoot the steps. So defined the following names (Formulas > Name Manager > New)
| Name |
Refers to: |
| _0_unsorted_input |
=Sheet1!$B$4:$B$500 replace with your input range |
| _0i_input_index |
=ROW(_0_unsorted_input) - (ROW(INDEX(_0_unsorted_input, 1, 1))) + 1 |
| _1_trimmed_input |
=TRIM(_0_unsorted_input) |
| _2_matched |
=MATCH(_1_trimmed_input,_1_trimmed_input,0) |
| _3_freq |
=FREQUENCY(_2_matched, _2_matched) |
| _4_uniq |
=INDEX(_1_trimmed_input,_5_uniq_index) |
| _4_uniq_range |
=Sheet1!$D$4:$D$500 a range with same number of rows as input |
| _5_uniq_index |
=IF((_0_unsorted_input <> """") * (_3_freq),_2_matched,"""") |
| _6_countif_less_than |
=IF((_4_uniq_range = "") + ISERROR(_4_uniq_range),"", COUNTIF(_4_uniq_range,"<" & _4_uniq_range)) |
| _7_sorted_index |
=SMALL(IF(ISERROR(_4_uniq_range),"",_6_countif_less_than),_0i_input_index) |
| _8_interim_sort |
=INDEX(_4_uniq_range,MATCH(_7_sorted_index,_6_countif_less_than,0)) |
| _8_interim_sort_range |
=Sheet1!$E$4:$E$500 a range with same number of rows as input |
| _9_sorted |
=INDEX(_8_interim_sort_range,1,1):INDEX(_8_interim_sort_range,MATCH(TRUE,ISERROR(_8_interim_sort_range),0)-1,1) |
Steps using COUNTIF and the last step to remove blanks require a range as input. So enter the formulas for these steps and one for the final result, here's how they are entered for the example:
These are array formulas and need to be entered with Control + Shift + Enter
| Cell |
Formula |
| D4, with D4:D500 selected |
= _4_uniq |
| E4, with E4:E500 selected |
= _8_interim_sort |
| F4 |
= _9_sorted |
I have tested this under Excel for Microsoft 365 - will test under Excel 2016 tomorrow.

