IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

filtre sur plusieurs Combobox [XL-2003]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mai 2009
    Messages : 17
    Par défaut filtre sur plusieurs Combobox
    Bonjour à tous,

    Après avoir regardé les tutos et autres sujet du forum, je n'ai pas réussit à répondre à ma question, peut être est elle bête j'en suis désolée par avance.

    Voilà j'ai fichier excel contenant pas mal de données. Afin de les retrouver plus vite je crée une interface à l'aide d'une macro et de combobox. J'aimerais avoir des combobox "maitre esclave", ça j'ai réussit à faire plus ou moins (j'ai réussit à remplir les combobox). Le problème est que mon tableau s'organise de la façon suivante:
    toto1
    bobo
    boubou
    baba
    toto2
    plif
    plaf
    plouf
    j'aimerais savoir si il est possible de programmer les Combobox, de façon à ce que lorsque je sélectionne avec la Combobox1, toto1, la combobox2 me laisse juste la possibilité de choisir entre les 3 possibilité (bobo, boubou, baba). Une espèce de filtre en faite?
    J'ai quatre niveau comme cela de combobox mais je pense que si j'y arrive déjà avec 2, le reste coule de source

    Merci de votre réponse

    Je vous met mon code au cas où cas ou!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    Option Explicit
    Dim NbLignes As Integer
     
     
    Private Sub UserForm_Initialize()
    Dim j As Long
    Dim kol As New Collection
     
    NbLignes = Cells(Rows.Count, 1).End(xlUp).row
    For j = 2 To NbLignes
        On Error Resume Next
        kol.Add Range("A" & j).Value, Range("A" & j).Value
    Next j
     
    For j = 2 To kol.Count
        Me.ComboBox1.AddItem kol(j)
    Next j
     
    End Sub
     
     
    Private Sub ComboBox1_Change()
    Dim j As Long
    Dim kol As New Collection
     
    For j = 2 To NbLignes
        On Error Resume Next
        If CStr(Range("A" & j).Value) Then kol.Add Range("B" & j).Value, Range("B" & j).Value
    Next j
    Me.ComboBox2.Clear
    For j = 1 To kol.Count
        Me.ComboBox2.AddItem kol(j)
    Next j
    End Sub
     
     
    Private Sub ComboBox2_Change()
    Dim j As Long
    Dim kol As New Collection
     
    For j = 2 To NbLignes
        On Error Resume Next
        If Me.ComboBox1.Value And Me.ComboBox2.Value Then kol.Add Range("C" & j).Value, Range("C" & j).Value
    Next j
    Me.ComboBox3.Clear
    For j = 1 To kol.Count
        Me.ComboBox3.AddItem kol(j)
    Next j
    End Sub
     
    Private Sub ComboBox3_Change()
    Dim j As Long
    Dim kol As New Collection
     
    For j = 2 To NbLignes
        On Error Resume Next
        If Me.ComboBox1.Value And Me.ComboBox2.Value And Me.ComboBox3.Value Then kol.Add Range("D" & j).Value, Range("D" & j).Value
    Next j
    Me.ComboBox4.Clear
    For j = 1 To kol.Count
        Me.ComboBox4.AddItem kol(j)
    Next j
    End Sub

  2. #2
    Membre Expert Avatar de mayekeul
    Inscrit en
    Août 2005
    Messages
    1 369
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 1 369
    Par défaut
    bonjour,

    en substance, je ferai un truc dans le genre pour gérer ça comme tu le souhaite.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    Sub Combo1_Change()
      'vider combo box 2, 3 et 4
      Combo2.Clear
      Combo3.Clear
      Combo4.Clear
      Select Case Combo1
        case A
          'remplir combobox2
          'ton code
        Case B
          'remplir combobox2
          'ton code      
        Case C
          'remplir combobox2
          'ton code
        Case D
          'remplir combobox2
          'ton code
        Case ...
      End Select
    End Sub
     
    Sub Combo2_Change()
      'vider combo box  3 et 4
      Combo3.Clear
      Combo4.Clear
      Select Case Combo2
        case A
          'remplir combobox3
          'ton code
        Case B
          'remplir combobox3
          'ton code      
        Case C
          'remplir combobox3
          'ton code
        Case D
          'remplir combobox3
          'ton code
        Case ...
      End Select
    End Sub
     
    Sub Combo3_Change()
      'vider combo box  4
      Combo4.Clear
      Select Case Combo3
        case A
          'remplir combobox4
          'ton code
        Case B
          'remplir combobox4
          'ton code      
        Case C
          'remplir combobox4
          'ton code
        Case D
          'remplir combobox4
          'ton code
        Case ...
      End Select
    End Sub

  3. #3
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    Option Explicit
    Dim LastLig As Long
     
    Private Sub UserForm_Initialize()
    Dim i As Long
    With Sheets("Feuil1")
        LastLig = .Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To LastLig
            Me.ComboBox1 = .Range("A" & i).Value
            If Me.ComboBox1.ListIndex = -1 Then Me.ComboBox1.AddItem .Range("A" & i).Value
        Next i
        Me.ComboBox1.ListIndex = -1
    End With
    End Sub
     
    Private Sub ComboBox1_Change()
    Dim i As Long
    With Sheets("Feuil1")
        Me.ComboBox2.Clear
        LastLig = .Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To LastLig
            If .Range("A" & i).Value <> Me.ComboBox1 Then
                Me.ComboBox2 = .Range("A" & i).Value
                If Me.ComboBox2.ListIndex = -1 Then Me.ComboBox2.AddItem .Range("A" & i).Value
            End If
        Next i
        Me.ComboBox2.ListIndex = -1
    End With
    End Sub
     
    Private Sub ComboBox2_Change()
    Dim i As Long
    With Sheets("Feuil1")
        Me.ComboBox3.Clear
        LastLig = .Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To LastLig
            If .Range("A" & i).Value <> Me.ComboBox1 And .Range("A" & i).Value <> Me.ComboBox2 Then
                Me.ComboBox3 = .Range("A" & i).Value
                If Me.ComboBox3.ListIndex = -1 Then Me.ComboBox3.AddItem .Range("A" & i).Value
            End If
        Next i
        Me.ComboBox3.ListIndex = -1
    End With
    End Sub

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mai 2009
    Messages : 17
    Par défaut
    Merci beaucoup! ça marche nickel!

  5. #5
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Oups, éliminer la définition de LatLig dans les combo change, c'est de trop
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    Option Explicit
    Dim LastLig As Long
     
    Private Sub UserForm_Initialize()
    Dim i As Long
    With Sheets("Feuil1")
        LastLig = .Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To LastLig
            Me.ComboBox1 = .Range("A" & i).Value
            If Me.ComboBox1.ListIndex = -1 Then Me.ComboBox1.AddItem .Range("A" & i).Value
        Next i
        Me.ComboBox1.ListIndex = -1
    End With
    End Sub
     
    Private Sub ComboBox1_Change()
    Dim i As Long
    With Sheets("Feuil1")
        Me.ComboBox2.Clear
        For i = 2 To LastLig
            If .Range("A" & i).Value <> Me.ComboBox1 Then
                Me.ComboBox2 = .Range("A" & i).Value
                If Me.ComboBox2.ListIndex = -1 Then Me.ComboBox2.AddItem .Range("A" & i).Value
            End If
        Next i
        Me.ComboBox2.ListIndex = -1
    End With
    End Sub
     
    Private Sub ComboBox2_Change()
    Dim i As Long
    With Sheets("Feuil1")
        Me.ComboBox3.Clear
        For i = 2 To LastLig
            If .Range("A" & i).Value <> Me.ComboBox1 And .Range("A" & i).Value <> Me.ComboBox2 Then
                Me.ComboBox3 = .Range("A" & i).Value
                If Me.ComboBox3.ListIndex = -1 Then Me.ComboBox3.AddItem .Range("A" & i).Value
            End If
        Next i
        Me.ComboBox3.ListIndex = -1
    End With
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [WD7.5] filtre sur plusieurs valeurs
    Par paupiau dans le forum WinDev
    Réponses: 7
    Dernier message: 20/06/2008, 15h12
  2. Filtres sur plusieurs champs/criteres en meme temps
    Par jeo13 dans le forum Macros et VBA Excel
    Réponses: 35
    Dernier message: 26/03/2008, 14h23
  3. filtre sur plusieurs colonnes en vba
    Par caloumaya dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 31/05/2007, 14h05
  4. [VBA Excel] Filtre sur plusieurs critères
    Par tazmania dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 06/12/2006, 11h12
  5. [VBA-E]filtre sur plusieurs Critères avec Excel
    Par Diablo_22 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 29/05/2006, 20h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo