Combobox en cascade - doublons á masquer

Bonjour à tous,

J'ai enfin réussi à alimenter trois combobox

Merci à GMB qui a partagé un exemple ici :

https://forum.excel-pratique.com/viewtopic.php?f=2&t=95514&p=552812&hilit=combobox+camion#p552812

La première Combobox affiche la colonne A sans doublons. Parfait !

J'aimerai faire pareil, sans doublons, pour les Combobox2 et 3.

J'ai essayé de faire un test mais sans résultat.

Private Sub ComboBox1_Change()

    ComboBox2.Clear
    For i = 5 To fr.Range("A" & Rows.Count).End(xlUp).Row

        If fr.Range("A" & i) = ComboBox1 Then
            If ComboBox2.ListIndex = -1 Then ComboBox2.AddItem fr.Range("B" & i) ' test doublon aucun effets
        End If
    Next i

End Sub

Merci par avance pour votre aide.

Le fichier si nécessaire :

56test-3-copie.xlsm (121.35 Ko)

Bon,jour,

pour le second :

Private Sub ComboBox1_Change()

    Set fr = Sheets("produits")
    ComboBox2.Clear
    Set dico = CreateObject("Scripting.Dictionary")
    For i = 5 To fr.Range("A" & Rows.Count).End(xlUp).Row

        If fr.Range("A" & i) = ComboBox1.Text Then
            dico(fr.Range("B" & i).Value) = ""
        End If
    Next i

    ComboBox2.List = dico.keys

End Sub

pour le troisième, idem

Private Sub ComboBox2_Change()

    Set fr = Sheets("produits")
    ComboBox3.Clear
    Set dico = CreateObject("Scripting.Dictionary")
    For i = 5 To fr.Range("A" & Rows.Count).End(xlUp).Row

        If fr.Range("A" & i) = ComboBox1.Text And fr.Range("B" & i) = ComboBox2.Text Then
            dico(fr.Range("C" & i).Value) = ""
        End If
    Next i

    ComboBox3.List = dico.keys

End Sub

Bonjour à tous

Ma petite participation

Option Explicit
Function Liste(choix As Integer)
    Dim d As Object, chx1$, chx2$, i%
    Set d = CreateObject("Scripting.Dictionary")
    Select Case choix
        Case 1
            With [F]
                For i = 1 To .Rows.Count
                    d(.Cells(i, 1).Value) = ""
                Next i
            End With
        Case 2
            chx1 = ComboBox1.Value
            With [SF]
                For i = 1 To .Rows.Count
                    If .Cells(i, 0) = chx1 Then
                        d(.Cells(i, 1).Value) = ""
                    End If
                Next i
            End With
        Case 3
            chx1 = ComboBox1.Value: chx2 = ComboBox2.Value
            With [Lib]
                For i = 1 To .Rows.Count
                    If .Cells(i, -3) = chx1 And .Cells(i, -2) = chx2 Then
                        d(.Cells(i, 1).Value) = ""
                    End If
                Next i
            End With
    End Select
    Liste = d.keys
End Function

Private Sub ComboBox1_Change()
    ComboBox2.Clear
    ComboBox3.Clear
    If ComboBox1.ListIndex > -1 Then ComboBox2.List = Liste(2)
End Sub

Private Sub ComboBox2_Change()
    ComboBox3.Clear
    If ComboBox2.ListIndex > -1 Then ComboBox3.List = Liste(3)
End Sub

Private Sub UserForm_Initialize()
    ComboBox1.List = Liste(1)
End Sub
58test-3-copie.xlsm (120.39 Ko)

Merci à vous deux pour vos réponses. C'est top !

Je vais opter pour la réponse de Steelson. Le code est plus abordable pour moi.

Ne m'en veut pas M12 ton fichier sera gardé bien au chaud, je vais m'amuser à déchiffrer tout ça.

Rechercher des sujets similaires à "combobox cascade doublons masquer"