Substitute for UNIQUE Dynamic Array to function properly in Excel 2019

StarAMI

New Member
Joined
Jul 7, 2023
Messages
3
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I created a workbook in which I use the UNIQUE dynamic array to extract each unique value from one column and enter it in another column. Unfortunately, I've discovered that some of the people who will need to use this workbook are still using Excel 2019, so the UNIQUE formula won't work for them. I've searched for an option that will manifest the same result that's compatible with earlier versions of Excel, but I can't find anything that works. I'm no Excel wizard, just someone who generally can find the information I need to make a spreadsheet do what I need it to do. :|

The original formula is =UNIQUE(W11:W35,FALSE,FALSE). It looks at the data in column W and returns each unique value one time in column N. Any suggestions for an alternative that will do the same thing, but in a way that's compatible with previous Excel versions?

Thanks in advance for any assistance.
 

Attachments

  • Unique formula.png
    Unique formula.png
    13.9 KB · Views: 109

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I'm not aware of any alternative for 2019 (or earlier) that will Spill the way that Unique will do, however, the following does return unique values (but you need to copy to enough cells to cover all possibilities). May need to enter with CSE.
Book1
NOPQRSTUVW
11123
12456
13789
14123
15456
16789
17123
18456
19789
20123
21456
22789
23123
24456
25789
26123
27456
28789
29123
30456
31789
32123
33456
34789
35123
36
37
38
39
40
41
42
43123
44456
45789
46 
47 
Sheet1
Cell Formulas
RangeFormula
N43:N47N43=IFERROR(INDEX($W$11:$W$35,MATCH(0,COUNTIF($N$42:N42,$W$11:$W$35),0)),"")
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Solution
A standard-entry alternative would be:

23 07 08.xlsm
NW
11123
12456
13789
14123
15456
16789
17123
18456
19789
20123
21456
22789
23123
24456
25789
26123
27456
28789
29123
30456
31789
32123
33456
34789
35123
36
41
42
43123
44456
45789
46 
Unique
Cell Formulas
RangeFormula
N43:N46N43=IFERROR(INDEX(W:W,AGGREGATE(15,6,ROW(W$11:W$35)/ISNA(MATCH(W$11:W$35,N$42:N42,0)),1)),"")
 
Upvote 0
The following is a UDF from my tool box to handle the UNIQUE function on older versions of Excel:

VBA Code:
Function UNIQUE(array_range As Variant, Optional by_col As Boolean = False, Optional exactly_once As Boolean = False) As Variant    ' Excel 2021
'
    Dim ArrayColumn                 As Long, ArrayRow           As Long
    Dim ArrayDimensionFoundValue    As Long, MaximumDimension   As Long
    Dim dict                        As Object
    Dim ConcatString                As String
    Dim key                         As Variant, SplitKeyArray   As Variant
    Dim OutputArray                 As Variant, TempArray       As Variant
'
    Set dict = CreateObject("Scripting.Dictionary")                                                                 ' Establish the dictionary
'
    If TypeName(array_range) = "Range" Then                                                                         ' If array_range is a range instead of an array then ...
        array_range = array_range.value2                                                                            '   Convert/Save the array_range values to 2D array array_range
    Else                                                                                                            ' Else ...
'
' Get # of dimensions of a passed array
        On Error Resume Next                                                                                        '   If error occurs in next few lines, ignore it & proceed to next line
            Do Until ArrayDimensionFoundValue = 999                                                                 '       Loop until ArrayDimensionFoundValue = 999
                MaximumDimension = MaximumDimension + 1                                                             '           Increment MaximumDimension
                ArrayDimensionFoundValue = 999                                                                      '           Set ArrayDimensionFoundValue = 999
                ArrayDimensionFoundValue = UBound(array_range, MaximumDimension)                                    '           Test to see if the incremented dimension in array_range exists
            Loop                                                                                                    '       Loop back
        On Error GoTo 0                                                                                             '   Return error handling back to Excel
'
        MaximumDimension = MaximumDimension - 1                                                                     '   Correct MaximumDimension to the correct dimension value of array_range
    End If
'
    If MaximumDimension = 1 Then                                                                                    ' If array_range is a 1D array then ...
        ReDim TempArray(1 To 1, 1 To UBound(array_range))                                                           '   Create 2D TempArray to store the values from the 1D array_range
'
        For ArrayColumn = 1 To UBound(array_range)                                                                  '   Loop through columns of array_range
            TempArray(1, ArrayColumn) = array_range(ArrayColumn)                                                    '       Save the values from array_range to TempArray
        Next                                                                                                        '   Loop back
'
        array_range = TempArray                                                                                     '   Save TempArray back to array_range, this will make array_range a 2D array
    End If
'-------------------------------------------------------------------------------------------------------------------
    If by_col = False Then                                                                                          '
'
' by_col = False ... Get all unique rows
        For ArrayRow = LBound(array_range, 1) To UBound(array_range, 1)                                             '   Loop through rows of array_range
            For ArrayColumn = LBound(array_range, 2) To UBound(array_range, 2)                                      '       Loop through columns of array_range
                If ConcatString <> vbNullString Then                                                                '           If ConcatString is not blank then ...
                    ConcatString = ConcatString & Chr(2) & array_range(ArrayRow, ArrayColumn)                       '               Append delimiter & the value from array_range to ConcatString
                Else                                                                                                '           Else ...
                    ConcatString = array_range(ArrayRow, ArrayColumn)                                               '               Save the value from array_range to ConcatString
                End If
            Next                                                                                                    '       Loop back
'
            If Not dict.exists(ConcatString) Then                                                                   '       If ConcatString is unique to what has been saved to the dictionary then ...
                dict.Add ConcatString, 1                                                                            '           Add it to the dictionary along with a counter value of 1
            Else                                                                                                    '       Else ...
                dict(ConcatString) = dict(ConcatString) + 1                                                         '           Increment the counter value for that ConcatString
            End If
'
            ConcatString = vbNullString                                                                             '       Clear ConcatString
        Next                                                                                                        '   Loop back
'
        ReDim OutputArray(1 To dict.Count, 1 To UBound(array_range, 2))                                             '   Set OutputArray to the proper row & column size needed
'
        ArrayRow = 0                                                                                                '   Reset ArrayRow
'
        For Each key In dict.keys                                                                                   '   Loop through the keys in the dictionary
            If exactly_once = False Then                                                                            '
                SplitKeyArray = Split(key, Chr(2))                                                                  '           Split ConcatString by delimiter into 1D Zero based SplitKeyArray
'
                ArrayRow = ArrayRow + 1                                                                             '           Increment ArrayRow
'
                For ArrayColumn = 1 To UBound(SplitKeyArray) + 1                                                    '           Loop through the columns of SplitKeyArray
                    OutputArray(ArrayRow, ArrayColumn) = SplitKeyArray(ArrayColumn - 1)                             '               Save each column value from SplitKeyArray into OutputArray
                Next                                                                                                '           Loop back
            Else                                                                                                    '       Else ...
                If dict(key) = 1 Then                                                                               '           If the ConcatString was only seen 1 time then ...
                    SplitKeyArray = Split(key, Chr(2))                                                              '               Split ConcatString by delimiter into 1D Zero based SplitKeyArray
'
                    ArrayRow = ArrayRow + 1                                                                         '               Increment ArrayRow
'
                    For ArrayColumn = 1 To UBound(SplitKeyArray) + 1                                                '               Loop through the columns of SplitKeyArray
                        OutputArray(ArrayRow, ArrayColumn) = SplitKeyArray(ArrayColumn - 1)                         '                   Save each column value from SplitKeyArray into OutputArray
                    Next                                                                                            '               Loop back
                End If
            End If
        Next                                                                                                        '   Loop back
    Else                                                                                                            ' Else ...
'-------------------------------------------------------------------------------------------------------------------
'
' by_col = True ... Get all unique columns
        For ArrayColumn = LBound(array_range, 2) To UBound(array_range, 2)                                          '   Loop through columns of array_range
            For ArrayRow = LBound(array_range, 1) To UBound(array_range, 1)                                         '       Loop through rows of array_range
                If ConcatString <> vbNullString Then                                                                '           If ConcatString is not blank then ...
                    ConcatString = ConcatString & Chr(2) & array_range(ArrayRow, ArrayColumn)                       '               Append delimiter & the value from array_range to ConcatString
                Else                                                                                                '           Else ...
                    ConcatString = array_range(ArrayRow, ArrayColumn)                                               '               Save the value from array_range to ConcatString
                End If
            Next                                                                                                    '       Loop back
'
            If Not dict.exists(ConcatString) Then                                                                   '       If ConcatString is unique to what has been saved to the dictionary then ...
                dict.Add ConcatString, 1                                                                            '           Add it to the dictionary along with a counter value of 1
            Else                                                                                                    '       Else ...
                dict(ConcatString) = dict(ConcatString) + 1                                                         '           Increment the counter value for that ConcatString
            End If
'
            ConcatString = vbNullString                                                                             '       Clear ConcatString
        Next                                                                                                        '   Loop back
'
        ReDim OutputArray(1 To UBound(array_range, 1), 1 To dict.Count)                                             '   Set OutputArray to the proper row & column size needed
'
        ArrayColumn = 0                                                                                             '   Reset ArrayColumn
'
        For Each key In dict.keys                                                                                   '   Loop through the keys in the dictionary
            If exactly_once = False Then                                                                            '
                SplitKeyArray = Split(key, Chr(2))                                                                  '           Split ConcatString by delimiter into 1D Zero based SplitKeyArray
'
                ArrayColumn = ArrayColumn + 1                                                                       '           Increment ArrayColumn
'
                For ArrayRow = 1 To UBound(SplitKeyArray) + 1                                                       '           Loop through the rows of SplitKeyArray
                    OutputArray(ArrayRow, ArrayColumn) = SplitKeyArray(ArrayRow - 1)                                '               Save each row value from SplitKeyArray into OutputArray
                Next                                                                                                '           Loop back
            Else                                                                                                    '       Else ...
                If dict(key) = 1 Then                                                                               '           If the ConcatString was only seen 1 time then ...
                    SplitKeyArray = Split(key, Chr(2))                                                              '               Split ConcatString by delimiter into 1D Zero based SplitKeyArray
'
                    ArrayColumn = ArrayColumn + 1                                                                   '               Increment ArrayColumn
'
                    For ArrayRow = 1 To UBound(SplitKeyArray) + 1                                                   '               Loop through the rows of SplitKeyArray
                        OutputArray(ArrayRow, ArrayColumn) = SplitKeyArray(ArrayRow - 1)                            '                   Save each row value from SplitKeyArray into OutputArray
                    Next                                                                                            '               Loop back
                End If
            End If
        Next                                                                                                        '   Loop back
    End If
'
    UNIQUE = OutputArray                                                                                            '
End Function


Excel Functions for older versions of Excel.xlsm
NOPQRSTUVW
10
11123
12456
13789
14123
15456
16789
17123
18456
19789
20123
21456
22789
23123
24456
25789
26123
27456
28789
29123
30456
31789
32123
33456
34789
35123
36
37
38
39
40
41
42
43123
44456
45789
Sheet2
Cell Formulas
RangeFormula
N43:N45N43=UNIQUE(W11:W35,FALSE,FALSE)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
I'm not aware of any alternative for 2019 (or earlier) that will Spill the way that Unique will do, however, the following does return unique values (but you need to copy to enough cells to cover all possibilities). May need to enter with CSE.
Thank you so much @kevin9999. This worked perfectly for my use.
 
Upvote 0
Thanks to everyone who responded with the gift of your knowledge. I have been able to resolve my issue using @kevin9999's suggested formula.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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