If you are not using an old veeeery machine or if you have a XL2007 worksheet with basillion rows, the cycle will be fast enough. Honestly!
Do not believe me? Look at it. I filled a range of a million lines with random letters using this:
=CHAR(RANDBETWEEN(65,90))
Then I wrote this function and called it from a range of 26 cells using Control-Shift-Enter:
=TRANSPOSE(UniqueChars(A1:A1000000))
Here's a not-so-optimized VBA function that I cracked in a couple of minutes:
Option Explicit
Public Function UniqueChars(rng As Range)
Dim dict As New Dictionary
Dim vals
Dim row As Long
Dim started As Single
started = Timer
vals = rng.Value2
For row = LBound(vals, 1) To UBound(vals, 1)
If dict.Exists(vals(row, 1)) Then
Else
dict.Add vals(row, 1), vals(row, 1)
End If
Next
UniqueChars = dict.Items
Debug.Print Timer - started
End Function
On my annual 2GHz Core 2 Duo T7300 laptop, it took 0.58 seconds.
source
share