I'm removing duplicated strings from an array and I'm pretty sure I need to use the Redim statement to dynamically change the size of the array, but I can't get it to work right.
Here's what I tried:
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
redim preserve... otherwise please detail what you think is not working. alsotemp(j = j + 1)wont work... makej = j +1before that and then dotemp(j).Dictionaryinstead; dictionary keys are inherently unique, and I'm pretty sure it's a O(1) hash lookup to determine whether a key exists - compared to O(n) for every element you lookup in an array. You'll want to reference the Microsoft Scripting Runtime library.