NEW Unique function - multiple arrays

gcefaloni

Board Regular
Joined
Mar 15, 2016
Messages
119
Hi!

Is it possible to use the new "unique" function on multiple non-contiguous arrays? If so, what would be the proper syntax to make it work?

As an example:
I'd like to do something like:
=UNIQUE({'Sheet1'!A1:A10,'Sheet2'!A1:A10}) where both Sheet 1 and Sheet 2 column As have the same type of data and have common data points. I want the unique ones to show up in a single array.

So, looking up unique values in non-contiguous arrays would be the objective. Is that doable?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Probably VBA or a UDF is cleaner. I tried this (ugly) approach which appears to work. The formula in A2 is filled down to A16.

Book6
ABCDEF
1Stack D-FUnique D-FNameNameName
2JamesJamesJamesJonesJackson
3JonesJonesJonesSmitheSmith
4WilliamWilliamWilliamJacksonJones
5WilliamsonWilliamsonWilliamsonJohnsonWilliamson
6WilliamSmitheWilliamBrownJohnson
7JonesJackson
8SmitheJohnson
9JacksonBrown
10JohnsonSmith
11Brown
12Jackson
13Smith
14Jones
15Williamson
16Johnson
Sheet1
Cell Formulas
RangeFormula
B2:B10B2=UNIQUE(A2:A16)
A2A2=IFERROR(INDEX($D$2:$D$6,ROWS(A2:$A$2)),IFERROR(INDEX($E$2:$E$6,ROWS(A2:$A$2)-ROWS($D$2:$D$6)),IFERROR(INDEX($F$2:$F$6,ROWS(A2:$A$2)-ROWS($D$2:$D$6)-ROWS($E$2:$E$6)),"")))
A3:A16A3=IFERROR(INDEX($D$2:$D$6,ROWS(A$2:$A3)),IFERROR(INDEX($E$2:$E$6,ROWS(A$2:$A3)-ROWS($D$2:$D$6)),IFERROR(INDEX($F$2:$F$6,ROWS(A$2:$A3)-ROWS($D$2:$D$6)-ROWS($E$2:$E$6)),"")))
Dynamic array formulas.
 
Last edited:
Upvote 0
Probably VBA or a UDF is cleaner. I tried this (ugly) approach which appears to work. The formula in A2 is filled down to A16.

Book6
ABCDEF
1Stack D-FUnique D-FNameNameName
2JamesJamesJamesJonesJackson
3JonesJonesJonesSmitheSmith
4WilliamWilliamWilliamJacksonJones
5WilliamsonWilliamsonWilliamsonJohnsonWilliamson
6WilliamSmitheWilliamBrownJohnson
7JonesJackson
8SmitheJohnson
9JacksonBrown
10JohnsonSmith
11Brown
12Jackson
13Smith
14Jones
15Williamson
16Johnson
Sheet1
Cell Formulas
RangeFormula
B2:B10B2=UNIQUE(A2:A16)
A2A2=IFERROR(INDEX($D$2:$D$6,ROWS(A2:$A$2)),IFERROR(INDEX($E$2:$E$6,ROWS(A2:$A$2)-ROWS($D$2:$D$6)),IFERROR(INDEX($F$2:$F$6,ROWS(A2:$A$2)-ROWS($D$2:$D$6)-ROWS($E$2:$E$6)),"")))
A3:A16A3=IFERROR(INDEX($D$2:$D$6,ROWS(A$2:$A3)),IFERROR(INDEX($E$2:$E$6,ROWS(A$2:$A3)-ROWS($D$2:$D$6)),IFERROR(INDEX($F$2:$F$6,ROWS(A$2:$A3)-ROWS($D$2:$D$6)-ROWS($E$2:$E$6)),"")))
Dynamic array formulas.

Would there be a way to nest the entire thing together? My solution right now, which is somewhat similar to yours I think, was to put in cell A2: =Unique("array1"), and put in cell A51: =Unique("array2") and then in cell B2: =Unique("A2:A100"). But like you said, it is quite ugly and I was hoping for a single formula rather than relying on a helper column.
 
Last edited:
Upvote 0
Maybe someone has another solution...possibly Microsoft will come up with UNIQUES sometime in the future.
 
Upvote 0

No. Not exactly. They are part of the same overall problem I'm trying to solve but they are different components. (1) is about finding the unique identifiers using formulas (I was thinking of using the Unique function) and the other question (2) is about merging results based on those merged identifiers. The second question I suppose could be solved with a simple sumifs. I'm not sure if there's a better way of doing it using arrays but the sumifs might work just fine. I'm still having issues with trying to solve (1) and use formulas to find unique "identifiers/tickers" without helper columns.
 
Upvote 0
No. Not exactly.
Thanks for the clarification.


If you want to use standard worksheet formulas then I think you will have to put up with helper cells. (happy to be proved wrong though)

If you do not want helper cells then you could employ a user-defined function like this:

VBA Code:
Function UniqueMult(ParamArray ranges() As Variant) As Variant
  Dim d As Object
  Dim rng As Variant
  Dim c As Range
 
  Set d = CreateObject("Scripting.Dictionary")
  For Each rng In ranges
    For Each c In rng
      If Len(c.Value) > 0 Then d(c.Value) = 1
    Next c
  Next rng
  UniqueMult = Application.Transpose(d.Keys)
End Function

The function needs only be entered in a single cell and the results should still 'spill' as required.
Sheet1
gcefaloni 2020-06-04 1.xlsm
A
1a
2b
3c
4b
5c
6a
7c
8a
9a
10c
Sheet1

Sheet2
gcefaloni 2020-06-04 1.xlsm
A
1a
2t
3r
4t
5r
6h
7t
8a
9t
10r
Sheet2

Sheet3
gcefaloni 2020-06-04 1.xlsm
A
1a
2b
3c
4t
5r
6h
7
8
9
10
Sheet3
Cell Formulas
RangeFormula
A1:A6A1=UniqueMult(Sheet1!A1:A10,Sheet2!A1:A10)
Dynamic array formulas.
 
Upvote 0
Hi!

Is it possible to use the new "unique" function on multiple non-contiguous arrays? If so, what would be the proper syntax to make it work?

As an example:
I'd like to do something like:
=UNIQUE({'Sheet1'!A1:A10,'Sheet2'!A1:A10}) where both Sheet 1 and Sheet 2 column As have the same type of data and have common data points. I want the unique ones to show up in a single array.

So, looking up unique values in non-contiguous arrays would be the objective. Is that doable?
Yes, you can easily do that by combining your arrays using VSTACK
=UNIQUE(VSTACK('Sheet1'!A1:A10,'Sheet2'!A1:A10))
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top