Microsoft 365 Userform faire 2 combobox en cascade + 1 listbox en fonction des combobox

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

Superemi

XLDnaute Junior
Bonjour à tous, le forum,

Je souhaite faire 1 combobox sur ma 1ère colonne sans doublon, puis en fonction de mon choix faire la 2ème combobox sur ma 2ème colonne.
Sur la Listbox apparait les critères correspondant à mes choix précédents.

Je me suis inspiré d'1 fichier trouvé sur internet, mais je n'arrive pas à alimenter ma 1ère combobox sur ma 1ère colonne (elle prend en compte les en-têtes de colonne).

1 fichier valant mieux que des mots, vous le trouverez en PJ avec les explications.

Par avance merci de votre aide.
Superemi
 

Pièces jointes

Bonjour @Superemi 🙂 ,

Un essai : voir le code associé à userform1 dans le fichier joint :
VB:
Option Explicit
Dim Nop As Boolean

Private Sub UserForm_Initialize()
Dim t, i&
    Nop = True
    t = Sheets("Listes").ListObjects(1).ListColumns(1).Range
    For i = 2 To UBound(t)
        ComboChoixColFiltre.Text = t(i, 1)
        If ComboChoixColFiltre.ListIndex = -1 Then ComboChoixColFiltre.AddItem t(i, 1)
    Next i
    ComboChoixColFiltre.Text = ""
    ListBox1.Clear
End Sub

Private Sub ComboChoixColFiltre_click()
Dim t, ref, i&
    Nop = True
    t = Sheets("Listes").ListObjects(1).ListColumns(1).Range.Resize(, 2)
    ComboBoxRech.Clear
    If ComboChoixColFiltre.ListIndex = -1 Then Exit Sub
    ref = ComboChoixColFiltre.Text
    For i = 2 To UBound(t)
        If ref = t(i, 1) Then
            ComboBoxRech.Text = t(i, 2)
            If ComboBoxRech.ListIndex = -1 Then ComboBoxRech.AddItem t(i, 2)
        End If
    Next i
    ComboBoxRech.Text = ""
    ListBox1.Clear
    Nop = False
End Sub

Private Sub ComboBoxRech_Change()
Dim ref1, ref2, t, i&, j&
    If Nop Then Exit Sub
    ListBox1.Clear
    ListBox1.ColumnCount = 5
    ListBox1.ColumnWidths = "150;40;40;40"
    If ComboBoxRech.ListIndex = -1 Then Exit Sub
    ref1 = ComboChoixColFiltre.Text: ref2 = ComboBoxRech.Text
    t = Sheets("Listes").ListObjects(1).ListColumns(1).Range.Resize(, 4)
    For i = 2 To UBound(t)
        If t(i, 1) = ref1 And t(i, 2) = ref2 Then
            ListBox1.AddItem t(i, 1)
            For j = 2 To 4: ListBox1.List(ListBox1.ListCount - 1, j - 1) = t(i, j): Next
        End If
    Next i
End Sub
 

Pièces jointes

Bonjour mapomme, ChTi160,

Vous avez été très rapide alors que ma réponse est tardive !
Après réflexion, j'ai retenu l'option de ChTi160 qui a l'option de tout afficher.

J'ai pu adapter sur mon fichier c'est parfait, merci à vous !

Cordialement,
Superemi
 
- 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
40
Affichages
2 K
Réponses
21
Affichages
2 K
Réponses
4
Affichages
904
Retour