使用VBA获取VBA中使用独特的价值? [英] Use VBA to get Unique values for use within VBA?
本文介绍了使用VBA获取VBA中使用独特的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前会使用这样的事情无论是与范围,细胞等许多不同的方式相同的基本原则。
I currently would use something like this either with Range, Cells or the like many different ways same basic principle.
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的对象,而无需复制到另一个位置?
Is there a way to directly load those unique values into any type of object in VBA without the need to copy to another location?
推荐答案
您可以使用集合对象
以创建独特的条目。例如:
You can use a Collection Object
to create unique entries. For example
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
截图
这篇关于使用VBA获取VBA中使用独特的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文