Charger listbox sans doublon

  • Initiateur de la discussion Initiateur de la discussion dam3117
  • 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 !

dam3117

XLDnaute Occasionnel
Bonjour,
Je cherche à alimenter une listbox à partir de ma feuille (macro ci-dessus), actuellement il me liste tout à partir de la date choisit.
je souhaiterai par compte même date même nom mettre une seule ligne dans ma listbox.

merci
dam


Sub recap()



Dim TheDate As Date ' Déclare les variables.
Dim Msg
Dim c As Long

Windows("base en projet.xls").Activate

Range("A1").Select

reponse = InputBox("Entrez une date (jj/mm/aaaa)", "Listing contrôle depuis le... ", Sheets("base").Range("A1"))
If IsDate(reponse) Then
TheDate = reponse
UserForm3.Label2 = Date - DateDiff("d", TheDate, Now)
UserForm3.Caption = "Récapitulatif des contrôles depuis le :" & TheDate
UserForm3.CommandButton2.Caption = "Mise en page du récapitulatif des contrôles depuis le: " & UserForm3.Label2.Caption
lafin = Worksheets("base").Range("A65536").End(xlUp).Row + 1
For n = 1 To lafin
If Worksheets("base").Range("A" & n) = CDate(UserForm3.Label2) Then
debut = n
Exit For
End If
Next n
If n = lafin + 1 Then
MsgBox ("La date n'existe pas!")
Call recap
Else
For n = debut To lafin
UserForm3.ListBox1.AddItem Worksheets("base").Range("a" & n).Text 'date

Next n
For n = 1 To UserForm3.ListBox1.ListCount - 1
UserForm3.ListBox1.List(n - 1, 1) = Worksheets("base").Range("b" & n + debut - 1) 'nom


UserForm3.ListBox1.List(n - 1, 2) = Worksheets("base").Range("c" & n + debut - 1) 'immat
Next n
UserForm3.Show
'UserForm3.CommandButton2_Click
End If
Else
If reponse = "" Then
Exit Sub
Else
MsgBox ("Format date incorrect!")
Call recap
End If

End If
 
Re : Charger listbox sans doublon

Salut Dam3117,

Sans fichier ce n'est pas simple, mais essaye avec ceci 😉
Code:
Sub recap()
  Dim MaCollection As New Collection  ' pour éviter les doublons
  Dim TheDate As Date  ' Déclare les variables.
  Dim Msg, Reponse
  Dim c As Long, n As Long
  Dim LigDeb As Long, LigFin As Long


  Windows("base en projet.xls").Activate


  Range("A1").Select


  Reponse = InputBox("Entrez une date (jj/mm/aaaa)", "Listing contrôle depuis le... ", Sheets("base").Range("A1"))
  If IsDate(Reponse) Then
    TheDate = Reponse
    UserForm3.Label2 = Date - DateDiff("d", TheDate, Now)
    UserForm3.Caption = "Récapitulatif des contrôles depuis le :" & TheDate
    UserForm3.CommandButton2.Caption = "Mise en page du récapitulatif des contrôles depuis le: " & UserForm3.Label2.Caption
    LigFin = Worksheets("base").Range("A65536").End(xlUp).Row + 1
    For n = 1 To LigFin
      If Worksheets("base").Range("A" & n) = CDate(UserForm3.Label2) Then
        LigDeb = n
        Exit For
      End If
    Next n
    If n = LigFin + 1 Then
      MsgBox ("La date n'existe pas!")
      Call recap
    Else
      For n = LigDeb To LigFin
        On Error Resume Next
          MaCollection.Add "item", Worksheets("base").Range("A" & n).Text
          If Err.Number = 0 Then
            With UserForm3.ListBox1
              .AddItem Worksheets("base").Range("a" & n).Text  'date
              .List(.ListCount, 1) = Worksheets("base").Range("b" & n + LigDeb - 1) 'nom
              .List(.ListCount, 2) = Worksheets("base").Range("c" & n + LigDeb - 1) 'immat
            End With
          End If
        On Error GoTo 0
      Next n
      UserForm3.Show
      'UserForm3.CommandButton2_Click
    End If
  Else
    If Reponse = "" Then
      Exit Sub
    Else
      MsgBox ("Format date incorrect!")
      Call recap
    End If


  End If
End Sub

A+
 
Re : Charger listbox sans doublon

Bonjour Bruno,

J'ai deux colonnes en A la date, en B le nom

mardi 12 juin 2012 AMANDINE OCEANE
mardi 12 juin 2012 ANDRE LEDUC
mardi 12 juin 2012 ARDENT
mardi 12 juin 2012 ANDRE LEDUC
mardi 12 juin 2012 ANSGAR
mardi 12 juin 2012 ANNEAU DE DIEU
mercredi 13 juin 2012 ANDRE LEDUC

je voudrai qu'il me charge la listbox sans doublon (une fois andre leduc pour le 12).

merci
dam
 
Re : Charger listbox sans doublon

Bonjour à tous,

je voudrai charger ma listbox sans doublon et avoir le résultat suivant.
données de la feuil1
12-juin emilie
12-juin emilie
12-juin titi
12-juin TOTO
13-juin emilie

résultat souhaité dans ma listbox
12-juin emilie
12-juin titi
12-juin TOTO
13-juin emilie

cdl
dam3317
 

Pièces jointes

- 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
10
Affichages
309
Réponses
5
Affichages
312
Réponses
8
Affichages
238
Réponses
4
Affichages
225
Retour