voici le code corrigé
ça fonctionne super !
- Code : Tout sélectionner
Function UniqueElements(PassedArray As Variant) As Variant
'// correction PassedArray fonctionne avec mieux avec un variant
Dim TempList List As Integer
Dim NewArray As Variant
Dim ArrayElement As String
Dim i As Integer
Dim Counter As Integer
On Error Goto handleError
For i = Lbound(PassedArray) To Ubound(PassedArray)
ArrayElement = PassedArray(i)
'// correction d'une petite faute orthographe sur les variables
TempList(ArrayElement) = 1
Next
Counter = Lbound(PassedArray)
'// correction ici, il manquait le redim initial
Redim NewArray(Counter)
Forall IndEntry In TempList
Redim Preserve NewArray(Counter)
NewArray(Counter) = Listtag(IndEntry)
Counter = Counter+1
End Forall
UniqueElements = NewArray
Exit Function
handleError:
Msgbox "Erreur n° " & Err & " - " & Error$ & " - ligne " & Erl,16,"Error UniqueElements"
Resume fin
fin:
End Function