Manipuler contenu Combobox

Bonjour à tous,

Je suis de retour avec une nouvelle questioonnn ... Bon voilà j'ai créé un userform sur lequel j'ai plusieurs combobox dont "cbocdcyon" qui devrait permettre d'afficher les noms des communautés de communes et le second "cbocomyon" qui en fonction de la communauté de communes choisie affiche uniquement les communes de cette communautés de communes.

Dans mon fichier excel, les communautés de communes sont dans la colonne D et les communes sont dans la colonne E. J'ai essayé le code suivant :

Private Sub UserForm_Initialize()

    Dim DerLigne_Cdc As String
    Dim Cell_Cdc As Range

     'Supprime les données existantes dans le ComboBox
     Me.cbocdcyon.Clear
     Me.cbocomyon.Clear

    DerLigne_Cdc = Range("D65536").End(xlUp).Address

    For Each Cell_Cdc In Worksheets("YON").Range("D2:" & DerLigne_Cdc)

    Me.cbocdcyon = Cell_Cdc

        'remplissage sans doublon
        If Me.cbocdcyon.ListIndex = -1 Then Me.cbocdcyon.AddItem Cell_Cdc

    Next Cell_Cdc

End Sub

Private Sub cbocomyon_Change()

Dim Cell_Cdc As Range
Dim DerLigne_Cdc As String

Me.cbocomyon.Clear

 If cbocdcyon.Text = "La Roche-sur-Yon-Agglomération" Then
            MsgBox ("Yes")
        For Each Cell_Cdc In Worksheets("YON").Range("D2:" & DerLigne_Cdc)

                If Cell_Cdc.Value Like "*Roche*" Then
                Me.cbocomyon.AddItem Cell_Cdc.Offset(0, 1)
                End If

        Next Cell_Cdc

 Else

      If cbocdcyon.Text = "Vie-et-Boulogne" Then
            MsgBox ("No")
         For Each Cell_Cdc In Worksheets("YON").Range("D2:" & DerLigne_Cdc)

                If Cell_Cdc.Value Like "*Roche*" Then
                Me.cbocomyon.AddItem Cell_Cdc.Offset(0, 1)

                End If

         Next Cell_Cdc
      End If

 End If

End Sub

Pourriez vous svp me dire où je me trompe ?

Merci d'avance.

Edit Dan : supprimé majuscules dans titre du sujet

Bonjour

Sans données confidentielles

Cordialement

Salut Dan,

Merci pour ta réponse .

Entretemps j'ai bidulé un truc qui marche pas trop mal.

Private Sub cbocdcyon_Change()

Dim Derligne_Cdc As String
Dim Cell_Cdc As Range
Derligne_Cdc = Sheets("YON").Range("D65536").End(xlUp).Address

cbocomyon.Clear
cbocomyon = ""

 If UCase(cbocdcyon.Text) = UCase(Range("D2").Value) Then
            MsgBox ("Yes")

        For Each Cell_Cdc In Worksheets("YON").Range("D2:" & Derligne_Cdc)

           If UCase(Cell_Cdc.Value) = UCase(Range("D2").Value) Then

                 Me.cbocomyon = Cell_Cdc.Offset(0, 1)

              If Me.cbocomyon.ListIndex = -1 Then Me.cbocomyon.AddItem Cell_Cdc.Offset(0, 1)

           End If

        Next Cell_Cdc
 Else

 Me.cbocomyon.Clear

  If UCase(cbocdcyon.Text) = UCase(Range("D150").Value) Then
            MsgBox ("No")

        For Each Cell_Cdc In Worksheets("YON").Range("D2:" & Derligne_Cdc)

           If UCase(Cell_Cdc.Value) = UCase(Range("D150").Value) Then

               Me.cbocomyon = Cell_Cdc.Offset(0, 1)

              If Me.cbocomyon.ListIndex = -1 Then Me.cbocomyon.AddItem Cell_Cdc.Offset(0, 1)

           End If

        Next Cell_Cdc

  End If
End If

End Sub

Avec dans D2 et D150 les valeurs que je souhaitais retrouver.

A + le forum

PS : Mais si quelq'un a un truc encore plus simple, je suis preneuse

Rechercher des sujets similaires à "manipuler contenu combobox"