@Bruno,
Bref, je trouvais ce code intéressant, mais j'ai bien compris qu'il ne fallait plus l'utiliser
J'utilise cet outil très souvent et la majorité n'a pas de complaints concernant cet erreur. Et s'ils l'ont, voilà la remedi avec le 3.5 ...
pour VBA < 2021-365 : SCA avec données unique trié
Private Sub UserForm_Initialize()
Dim Ar As Variant, SCA, i, j, c As Range
Set SCA = CreateObject("System.Collections.ArrayList")
With Sheets("Feuil1").Range("A1").CurrentRegion
On Error Resume Next
Set c = .Offset(1).Resize(.Rows.Count - 1) 'la plage dynamique
On Error GoTo 0
End With
If Not c Is Nothing Then
Ar = c.Value2
For j = 3 To 4 'boucle ces colonnes
SCA.Clear 'RAZ
For i = 1 To UBound(Ar) 'boucle les données
If Len(Ar(i, j)) Then If Not SCA.contains(Ar(i, j)) Then SCA.Add Ar(i, j) 'ajouter si ne pas vide
Next
SCA.Sort 'trier ascendant
If j = 3 Then ListBox1.List = SCA.toarray Else ListBox2.List = SCA.toarray 'ajouter au bon listbox
Next
End If
TextBox1.Text = Format(Date, "dd/mm/yyyy")
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
avec excel >= 2021-365, trier la matrice
Private Sub UserForm_Initialize()
Dim Ar As Variant, SCA, i, j, c As Range
Set dict = CreateObject("scripting.dictionary")
dict.comparemode = vbTextCompare
With Sheets("Feuil1").Range("A1").CurrentRegion
On Error Resume Next
Set c = .Offset(1).Resize(.Rows.Count - 1) 'la plage dynamique
On Error GoTo 0
End With
If Not c Is Nothing Then
Ar = c.Value2
For j = 3 To 4 'boucle ces colonnes
ar1 = Application.Sort(Ar, j) 'nouvelle matrice trié sur la colonne j
dict.RemoveAll
For i = 1 To UBound(Ar) 'boucle les données
If Len(ar1(i, j)) Then dict(ar1(i, j)) = 0
Next
If j = 3 Then ListBox1.List = dict.keys Else ListBox2.List = dict.keys 'ajouter au bon listbox
Next
End If
TextBox1.Text = Format(Date, "dd/mm/yyyy")
TextBox2.Text = ""
TextBox3.Text = ""
End Sub