我正在从数组中删除重复的字符串,我很确定我需要使用 Redim 语句来动态更改数组的大小,但我无法让它正常工作。
这是我尝试过的:
Dim temp() as String
Dim vetOrg as Variant
vetOrg = Array(contRows)
ReDim vetOrg(1 To contRows)
'populates the array
For i = 1 To contRows
vetOrg(i) = wsDeals.Cells(i + 1, 2).Value
Next i
j = 1
For i = 1 To contRows
ReDim temp(1 To j)
If vetOrg(i) <> vetOrg(i + 1) Then
temp(j = j + 1) = vetOrg(i)
End If
temp(j = j + 1) = vetOrg(contRows - 1)
Next i
最佳答案
与 Scripting.Dictionary
您无需担心调整大小或搜索重复值;字典键本质上是唯一的:
Dim vetOrg As Scripting.Dictionary
Set vetOrg = New Scripting.Dictionary
For i = 1 To contRows
vetOrg(wsDeals.Cells(i + 1, 2).Value) = i ' value is bogus, it's the key we want.
Next i
'done. vetOrg.Keys has the unique values.
关于excel - 如何在执行时设置动态数组大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56299003/