Listbox sans doublon

  • Initiateur de la discussion Initiateur de la discussion antiphot
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

antiphot

XLDnaute Occasionnel
Bonjour à toutes et à tous

J'aimerais alimenter une listbox sans doublon. Est ce qu'il est possible de le faire en gardant le code ci-dessous ou bien est il necessaire de tout remanier ?

Merci par avance pour vos conseils
Philippe
Code:
Sub RechDMaPlanifier()
Application.ScreenUpdating = False
Set ListeDM = Sheets("DmAttentePlanif").Range("A2:A" & Sheets("feuil1").Range("A65536").End(xlUp).Row)
With ListeDM
        Set c = .Find("D", LookIn:=xlValues)
           If Not c Is Nothing Then
                firstaddress = c.Address
                    Do
                        Set c = .FindNext(c)
                        
                        UserForm1.lbDMaPlanif.AddItem c.Offset(0, 1)
                        
                    Loop While Not c Is Nothing And c.Address <> firstaddress
            End If
End With
Call TriListbox(UserForm1.lbDMaPlanif)
Application.ScreenUpdating = True
End Sub
Private Sub TriListbox(oListe As Object)
    ' Tri de la liste
    Dim i As Long, j As Long
    Dim temp1 As String
    
    For i = 0 To oListe.ListCount - 1
        For j = 0 To oListe.ListCount - 1
            If oListe.List(i) < oListe.List(j) Then
                temp1 = oListe.List(i)
                oListe.List(i) = oListe.List(j)
                oListe.List(j) = temp1
            End If
        Next j
    Next i
End Sub
 
Re : Listbox sans doublon

Bon en fait je pense avoir trouvé la solution en utilisant .Dictionary

Code:
Sub RechDMaPlanifier()
Application.ScreenUpdating = False
Set ListeDM = Sheets("DmAttentePlanif").Range("A2:A" & Sheets("feuil1").Range("A65536").End(xlUp).Row)
 Set Dictionaire = CreateObject("Scripting.Dictionary")
    
With ListeDM
        Set c = .Find("D", LookIn:=xlValues)
           If Not c Is Nothing Then
                firstaddress = c.Address
                
                    Do
                    
                        Set c = .FindNext(c)
                        If Not Dictionaire.Exists(c.Offset(0, 1).Value) Then Dictionaire.Add c.Offset(0, 1).Value, c.Offset(0, 1).Value
                        
                       UserForm1.lbDMaPlanif.List = Dictionaire.items
                        
                        
                    Loop While Not c Is Nothing And c.Address <> firstaddress
                    
            End If
End With
Call TriListbox(UserForm1.lbDMaPlanif)
Application.ScreenUpdating = True
End Sub
 
Re : Listbox sans doublon

Bonjour,

Listes sans doublons triée

Code:
Private Sub UserForm_Initialize()
   Set MonDico = CreateObject("Scripting.Dictionary")
   For Each c In Range(Sheets("feuil1").[A2], Sheets("feuil1").[A65000].End(xlUp))
      If Not MonDico.Exists(c.Value) And c.Value <> "" Then MonDico.Add c.Value, c.Value
   Next c
   Me.ComboBox1.List = MonDico.items
End Sub

JB
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
15
Affichages
830
Réponses
10
Affichages
680
Réponses
5
Affichages
932
Retour