excel – vba:从数组中获取唯一值

是否在vba中内置了功能以从一维数组获取唯一值?如何摆脱重复?

如果不是,那么我将如何从数组获取唯一值?

This post包含2个示例。我喜欢第二个:

Sub unique() 
  Dim arr As New Collection, a 
  Dim aFirstArray() As Variant 
  Dim i As Long 

  aFirstArray() = Array("Banana", "Apple", "Orange", "Tomato", "Apple", _ 
  "Lemon", "Lime", "Lime", "Apple") 

  On Error Resume Next 
  For Each a In aFirstArray 
     arr.Add a, a 
  Next 

  For i = 1 To arr.Count 
     Cells(i, 1) = arr(i) 
  Next 

End Sub 
http://stackoverflow.com/questions/3017852/vba-get-unique-values-from-array

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:excel – vba:从数组中获取唯一值