Initialiser plusieurs ListBox dans un USF

Bonjour à tous,

Je travaille actuellement sur un petit USF me permettant de gérer ma micro-entreprise mais là je me retrouve bloqué sur un point.

https://www.cjoint.com/c/FCynTakqeMF

Comme vous le verrez sur le fichier ci-joint j'aimerais que mes 3 listbox contenus chacun dans une page soit alimenté dès l'ouverture de mon USF en allant chercher chacun des données dans les différentes sheet de mon tableur.

-ListBox1 = Sheet("Toto")
-ListBox2 = Sheet("lolo")
-ListBox3=Sheet("Velo")

J'ai réussi en fouillant sur ce forum pour le 1er ListBox mais je bloque pour les 2 autres, je vois pas comment faire pour dès l'initialisation de l'USF les 3 ListBox se chargent.

Merci d'avance pour ceux qui auront le temps d'y jeter un petit coup d'oeil.

Bonne journée à tous :)

4 réponses

  • Votes
  • Date
  • Date décroissante
  1. Merci Le Pivert,

    Je ferais cette solution si jamais je ne trouve pas de façon pour utiliser mes combobox pour trier.

    En effet je voulais au-dessus de chaque liste box avoir 6 combobox me permettant de faire des filtres successifs.Ce que j'ai réussi à faire pour ma listbox1.

    Si je ne trouve pas d'idée je ferais simplement sans filtre.
    1. Contributeur
      comme ceci:

      Private Sub UserForm_Initialize()
       Set f = Sheets("toto")
       Set bd = f.Range("a2:f" & f.[A65000].End(xlUp).Row)
       For c = 1 To 6
        ListeCol c
       Next c
       filtre
       Set f = Sheets("lolo")
       Set bd = f.Range("a2:f" & f.[A65000].End(xlUp).Row)
       For c = 1 To 6
        ListeCol c
       Next c
       filtre_2
        Set f = Sheets("velo")
       Set bd = f.Range("a2:f" & f.[A65000].End(xlUp).Row)
       For c = 1 To 6
        ListeCol c
       Next c
       filtre_3
      End Sub
      
      Sub filtre()
         ligne = 0
         Me.ListBox1.Clear
         For i = 1 To bd.Rows.Count
           ok = True
           For n = 1 To bd.Columns.Count
               If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
           Next n
           If ok Then
             Me.ListBox1.AddItem
             For k = 1 To bd.Columns.Count
               Me.ListBox1.List(ligne, k - 1) = bd.Cells(i, k)
             Next k
             Me.ListBox1.List(ligne, 6) = bd.Cells(i, k)
             ligne = ligne + 1
            End If
         Next i
      End Sub
      Sub filtre_2()
         ligne = 0
         Me.ListBox2.Clear
         For i = 1 To bd.Rows.Count
           ok = True
           For n = 1 To bd.Columns.Count
               If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
           Next n
           If ok Then
             Me.ListBox2.AddItem
             For k = 1 To bd.Columns.Count
               Me.ListBox2.List(ligne, k - 1) = bd.Cells(i, k)
             Next k
             Me.ListBox2.List(ligne, 6) = bd.Cells(i, k)
             ligne = ligne + 1
            End If
         Next i
      End Sub
      Sub filtre_3()
         ligne = 0
         Me.ListBox3.Clear
         For i = 1 To bd.Rows.Count
           ok = True
           For n = 1 To bd.Columns.Count
               If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
           Next n
           If ok Then
             Me.ListBox3.AddItem
             For k = 1 To bd.Columns.Count
               Me.ListBox3.List(ligne, k - 1) = bd.Cells(i, k)
             Next k
             Me.ListBox3.List(ligne, 6) = bd.Cells(i, k)
             ligne = ligne + 1
            End If
         Next i
      End Sub
      
      
      

      1. Super le Pivert,

        cela marche avec le code ci-dessous. Seul problème je ne peux pas filtrer avec les combobox des ListBox 2 et 3. Ca devient trop compliqué pour moi à ce stade là, je réfléchis sur votre code.

        Encore merci c'est vraiment sympa de votre part.

        Dim f, bd
        
        Private Sub UserForm_Initialize()
         Set f = Sheets("toto")
         Set bd = f.Range("a2:f" & f.[A65000].End(xlUp).Row)
         For c = 1 To 6
          ListeCol c
         Next c
         filtre
         Set f = Sheets("lolo")
         Set bd = f.Range("a2:f" & f.[A65000].End(xlUp).Row)
         For c = 1 To 6
          ListeCol c
         Next c
         filtre_2
          Set f = Sheets("velo")
         Set bd = f.Range("a2:f" & f.[A65000].End(xlUp).Row)
         For c = 1 To 6
          ListeCol c
         Next c
         filtre_3
        End Sub
        
        Sub filtre()
           ligne = 0
           Me.ListBox1.Clear
           For i = 1 To bd.Rows.Count
             ok = True
             For n = 1 To bd.Columns.Count
                 If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
             Next n
             If ok Then
               Me.ListBox1.AddItem
               For k = 1 To bd.Columns.Count
                 Me.ListBox1.List(ligne, k - 1) = bd.Cells(i, k)
               Next k
               Me.ListBox1.List(ligne, 6) = bd.Cells(i, k)
               ligne = ligne + 1
              End If
           Next i
        End Sub
        Sub filtre_2()
           ligne = 0
           Me.ListBox2.Clear
           For i = 1 To bd.Rows.Count
             ok = True
             For n = 1 To bd.Columns.Count
                 If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
             Next n
             If ok Then
               Me.ListBox2.AddItem
               For k = 1 To bd.Columns.Count
                 Me.ListBox2.List(ligne, k - 1) = bd.Cells(i, k)
               Next k
               Me.ListBox2.List(ligne, 6) = bd.Cells(i, k)
               ligne = ligne + 1
              End If
           Next i
        End Sub
        Sub filtre_3()
           ligne = 0
           Me.ListBox3.Clear
           For i = 1 To bd.Rows.Count
             ok = True
             For n = 1 To bd.Columns.Count
                 If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
             Next n
             If ok Then
               Me.ListBox3.AddItem
               For k = 1 To bd.Columns.Count
                 Me.ListBox3.List(ligne, k - 1) = bd.Cells(i, k)
               Next k
               Me.ListBox3.List(ligne, 6) = bd.Cells(i, k)
               ligne = ligne + 1
              End If
           Next i
        End Sub
        
        Sub ListeCol(noCol)
          Set MonDico = CreateObject("Scripting.Dictionary")
          For i = 1 To bd.Rows.Count
             ok = True
             For n = 1 To bd.Columns.Count
               If n <> noCol Then
                 If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
               End If
             Next n
             If ok Then
               tmp = bd.Cells(i, noCol)
               MonDico(tmp) = tmp
             End If
           Next i
           MonDico.Add "*", "*"
           temp = MonDico.items
           Call Tri(temp, LBound(temp), UBound(temp))
           Me("ComboBox" & noCol).List = temp
        End Sub
        Sub Tri(a, gauc, droi) ' Quick sort
        ref = CStr(a((gauc + droi) \ 2))
        g = gauc: d = droi
        Do
        Do While CStr(a(g)) < ref: g = g + 1: Loop
        Do While ref < CStr(a(d)): d = d - 1: Loop
        If g <= d Then
        temp = a(g): a(g) = a(d): a(d) = temp
        g = g + 1: d = d - 1
        End If
        Loop While g <= d
        If g < droi Then Call Tri(a, g, droi)
        If gauc < d Then Call Tri(a, gauc, d)
        End Sub