excelsortinguniquevstack

Excel SORT Function in Conjunction With UNIQUE, TOROW & VSTACK


I need to gather data from various ranges (only 2 ranges used in my example, but more ranges will be added), then display each result value only once in a row (ie no duplicate values) and then also display these results ascending order.

So far, I have managed to gather the data from the various ranges and display in 1 row using =SORT(UNIQUE(TOROW(VSTACK(B36:AF36,B67:AF67),1)),,1), but this formula is not SORTING ascending, nor is it only displaying each value once.

In my example:

B36:AF36 contains values 1, 2, 3, 8, 15

B67:AF67 contains values 4, 6, 15, 16

Current Outcome is displaying 1, 2, 3, 8, 15, 4, 6, 15, 16 (result of range 1 followed by result of range 2)

The desired outcome should be 1, 2, 3, 4, 6, 8, 15, 16 (result of Ranges 1 & 2 combined and sorted in ascending order, with duplicate values(i.e number 15 in this case) only displayed once.

Any help would be appreciated, bearing in mind that I also need to add more/other ranges into the formula.

Many Thanksscreenshot 1


Solution

  • 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.