Here is my code,
RemoveDuplicatesInArray don't work
Sub abcd()
Dim myArray
Dim exp As Integer
Dim i As Long
Dim arr
myArray = Range("A6").CurrentRegion
For i = 1 To UBound(myArray, 1)
Next i
arr = RemoveDuplicatesInArray(myArray)
For exp = LBound(arr) To UBound(arr)
UserForm1.ComboBox1.AddItem arr(exp, 1)
Next exp
UserForm1.Show
End Sub
Public Function RemoveDuplicatesInArray(the_array)
On Error Resume Next
p = 1
Do
Z = UBound(the_array, p)
p = p + 1
Loop While Err = 0
Err = 0
NumDimensions = p - 2
Dim newArray()
Select Case NumDimensions
Case 1
new_array_nb = 0
ReDim newArray(0 To 0)
For k = 0 To UBound(the_array)
Duplicate = 0
For x = 0 To k - 1
If the_array(x) = the_array(k) Then
Duplicate = 1
Exit For
End If
Next x
If Duplicate = 0 And IsEmpty(the_array(k)) = False Then
ReDim Preserve newArray(0 To new_array_nb)
newArray(new_array_nb) = the_array(k)
new_array_nb = new_array_nb + 1
End If
Next k
Case 2
the_dim = UBound(the_array, 1)
new_array_nb = 0
ReDim newArray(0 To the_dim, 0 To 0)
For k = 0 To UBound(the_array, 2)
Duplicate = 0
For x = 0 To k - 1
equal = 1
For eq = 0 To the_dim
If the_array(eq, x) <> the_array(eq, k) Then
equal = 0
Exit For
End If
Next eq
If equal = 1 Then
Duplicate = 1
End If
Next x
If Duplicate = 0 Then
ReDim Preserve newArray(0 To the_dim, 0 To new_array_nb)
For eq = 0 To the_dim
newArray(eq, new_array_nb) = the_array(eq, k)
Next eq
new_array_nb = new_array_nb + 1
End If
Next k
End Select
RemoveDuplicatesInArray = newArray
On Error GoTo 0
End Function
Bookmarks