Probleme de combobox dans formulaire

Bonjour,

Je n'arrive pas à récupérer dans mes combobox la liste des colonnes. Pourtant j'ai bien un onglet Base avec 4 colonnes 'A,B,C,D.
Le Formulaire se lance et rien dans les combo. Je vous met le code.

Option Explicit

Dim Ws As Worksheet
Dim NbLignes As Integer

Private Sub UserForm3_Initialize()
     Set Ws = Worksheets("Base")
     NbLignes = Ws.Range("A65536").End(xlUp).Row
  
    Alim_Combo 1
End Sub

Private Sub ComboBox1_Change()
      Alim_Combo 2, ComboBox1.Value
End Sub


Private Sub ComboBox2_Change()
    Alim_Combo 3, ComboBox2.Value
End Sub

Private Sub ComboBox3_Change()
    Alim_Combo 4, ComboBox3.Value
End Sub

Private Sub Alim_Combo(CbxIndex As Integer, Optional Cible As Variant)
    Dim j As Integer
    Dim Obj As Control
    Set Obj = Me.Controls("ComboBox" & CbxIndex)
    Obj.Clear
    If CbxIndex = 1 Then
        For j = 2 To NbLignes
            Obj = Ws.Range("A" & j)
            'Remplit le ComboBox sans doublons
            If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j)
        Next j
    Else
        For j = 2 To NbLignes
            If Ws.Range("A" & j).Offset(0, CbxIndex - 2) = Cible Then
                Obj = Ws.Range("A" & j).Offset(0, CbxIndex - 1)
                If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j).Offset(0, CbxIndex - 1)
            End If
        Next j
   End If
End Sub
Configuration: Windows XP
Firefox 2.1
EXCEL 2007

3 réponses

  • Votes
  • Date
  • Date décroissante
  1. salut,

    Je pense qu'il y a un problème à l'appel de la procédure Alim_Combo. Les paramètres à passer doivent être entre parenthèses :

    Call Alim_Combo (1)
    ...
    Call Alim_Combo (2, ComboBox1.Value)

    etc ...

    ;o)

    Polux
    1. Bonjour,

      Désolé mais cela ne fonctionne toujours pas. Ce que je ne comprends pas c'est que j'ai récupéré ce code sur le net et que je n'arrive pas à le mettre en application alors qu'il fonctionne dans le fichier exemple que j'ai ouvert sur excel. Si tu veux le fichier pour voir je peux te le passer.

      guyanais