xl get unique values code example
Example 1: xl get unique values
Function DistinctVals(a, Optional col = 1)
Dim i&, v: v = a
With CreateObject("Scripting.Dictionary")
For i = 1 To UBound(v): .Item(v(i, col)) = 1: Next
DistinctVals = Application.Transpose(.Keys)
End With
End Function
Function DistinctVals(r As Range)
DistinctVals = WorksheetFunction.Unique(r)
End Function
Example 2: xl get unique values
Function DistinctVals(a, Optional col = 1)
Dim i&, v: v = a
With CreateObject("Scripting.Dictionary")
For i = 1 To UBound(v): .Item(v(i, col)) = 1: Next
DistinctVals = Application.Transpose(.Keys)
End With
End Function
Function DistinctVals(r As Range)
DistinctVals = WorksheetFunction.Unique(r)
End Function