收集列中的所有名称,并将其放入Excel中的数组中

我对于excel和VBA很新,需要帮助解决这个问题。 问题是我有一个公司名称不同的专栏,例如苹果,微软,华硕,公司可能会多次使用。

如何在VBA中填充包含此列的不同成员的数组?

您可以使用不允许同一个键重复的vba collection

 Option Explicit Sub UniqueList() Dim i As Long Dim rList As Range Dim cUnique As New Collection Dim aFinal() As String 'change the range depending on the size of your title (or use a named range) Set rList = Range("A1:M1") 'Loop over every column and add the value to the collection (with unique key) For i = 1 To rList.Columns.Count On Error Resume Next cUnique.Add rList(1, i), CStr(rList(1, i)) Next i 'Store back the value from the collection to an array ReDim aFinal(1 To cUnique.Count, 1 To 1) For i = 1 To cUnique.Count aFinal(i, 1) = cUnique(i) Next i 'Use aFinal to do whatever you want End Sub