Option Compare Text
Public Function GetDistinct(rng As Range, Optional Trnsp As Boolean = True) As Variant()
Dim x, arr(), v, s As String, i As Long
x = Intersect(rng, rng.Worksheet.UsedRange).Value
ReDim arr(UBound(x)): s = "~"
For Each v In Intersect(rng, rng.Worksheet.UsedRange).Value
If Len(v) Then
If InStr(s, "~" & v & "~") = 0 Then
s = s & v & "~": arr(i) = v: i = i + 1
End If
End If
Next
GetDistinct = IIf(Trnsp, WorksheetFunction.Transpose(arr), arr())
End Function
|