i 本功能在去除第6条中的重复
Function FilterDuplicates(Arr As Variant) As Long
Dim col As Collection, index As Long, dups As Long
Set col = New Collection
On Error Resume Next
For index = LBound(Arr) To UBound(Arr)
build the key using the array element
an error occurs if the key already exists
col.Add 0, CStr(Arr(index))
If Err Then
we ve found a duplicate
Arr(index) = Empty
dups = dups + 1
Err.Clear
ElseIf dups Then
if we ve found one or more duplicates so far
we need to move elements towards lower indices
Arr(index - dups) = Arr(index)
Arr(index) = Empty
End If
Next
return the number of duplicates
FilterDuplicates = dups
End Function
I need to optimize this function to run faster, please help