我目前会使用Range,Cells等许多不同方式使用相同的基本原理。
Range("A1", Range("A1").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("IV1"), Unique:=True
Dim myArr as Variant
myArr = Range("IV1", Range("IV1").End(xlDown))
Columns("IV").Delete
有没有办法直接将这些唯一值加载到VBA中的任何类型的对象中而无需复制到其他位置?
答案 0 :(得分:6)
您可以使用Collection Object
创建唯一条目。例如
Sub Sample()
Dim Col As New Collection
Dim itm
Dim i As Long
Dim CellVal As Variant
'~~> Lets say looping through Row 1 to 22 For
'~~> Range("A1:A22") as mentioned in your recent comment
For i = 1 To 22
CellVal = Sheets("Sheet1").Range("A" & i).Value
On Error Resume Next
Col.Add CellVal, Chr(34) & CellVal & Chr(34)
On Error GoTo 0
Next i
For Each itm In Col
Debug.Print itm
Next
End Sub
<强>截图强>: