Q:

Get "Unique" in array without filtering on sheet

I extract unique values from a column and put them in an array with a code like this:
Range("A1:A27").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("Z1"), Unique:=True
Univoci = Range("Z1").CurrentRegion.Value

The question is: it's possible to put them directly into the array?
I mean with one command or with minimum code (I know that I can get unique values by comparing every item with the others)
Thanks in advance

A:

I'm not sure there is a way to initalise and fill an array with unique values off the bat, but you can use a dictionary to build up the unique entries
  Set Dict = CreateObject("Scripting.Dictionary")
  For Each Cell In Range("A1:A27")
    If Not Dict.Exists(Cell.Value) Then Dict.Add Cell.Value, Cell.Address
  Next

  Dim itemArray() As Variant
  ReDim itemArray(0 To Dict.Count - 1)
  For Each Value In Dict.Keys
    itemArray(i) = Value
    i = i + 1
  Next

You may not need to cast the dictionary into an array, as you could access the dictionary key values directly for further coding, which would cut down on the lines of code as well.

