Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel SORT Function in Conjunction With UNIQUE, TOROW & VSTACK

I need to extract unique values from multiple ranges (only two ranges in my example, but more will be added) and display them in a single row, sorted in ascending order, without duplicates.

So far, I have used the following formula:

=SORT(UNIQUE(TOROW(VSTACK(B36:AF36, B67:AF67),1)),,1)

However, this formula is not sorting the values correctly and not removing duplicates as expected.

Example:

Given Data:

B36:AF36 → {1, 2, 3, 8, 15}

B67:AF67 → {4, 6, 15, 16}

Current Output (Incorrect)

{1, 2, 3, 8, 15, 4, 6, 15, 16} (Concatenated but not sorted, and 15 appears twice)

Expected Output (Correct)

{1, 2, 3, 4, 6, 8, 15, 16} (Sorted in ascending order with duplicates removed)

What formula should I use to ensure that the values from all ranges are correctly combined, sorted, and displayed uniquely in a single row?

Thanks in advance for any help!

like image 448
cj69 Avatar asked Dec 09 '25 16:12

cj69


1 Answers

You were almost there:

=SORT(UNIQUE(HSTACK(A1:E1,A2:E2),TRUE),,,TRUE)

Make sure the functions you are using work in the same direction - horizontal or vertical:

enter image description here

  1. Stack your arrays horizontally
  2. Take unique values, make sure to use 'TRUE' to return unique columns
  3. Sort provided array by columns.

Edit: if empty cells have to be filtered out:

=LET(
input, HSTACK(B36:AF36,B67:AF67),
SORT(UNIQUE(FILTER(input,HSTACK(input)<>"",""),TRUE),,,TRUE))
like image 129
Michal Rosa Avatar answered Dec 11 '25 16:12

Michal Rosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!