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 :

Mon code filtre que les premiers choix de mes combobox


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Lycéen
    Inscrit en
    Février 2015
    Messages
    52
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Février 2015
    Messages : 52
    Par défaut Mon code filtre que les premiers choix de mes combobox
    Bonjour ,j'ai un problème mon code marche uniquement pour le premier choix offert par mon combobox , si je réalise un autre choix la valeur correspondante à ma colonne 12 est 0 et le filtre masque toutes les valeurs de mon tableau ??!!
    ici mon code et mon fichier en pièce jointe :Mon programme .xlsm

    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
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    Option Explicit
    'Définition des variables
    Dim Ws As Worksheet
    Dim NbLignes As Integer
    Dim typalim As String
    Dim modecon As String
    Dim typf As String
    Dim esp As String
    Dim cycl As String
    Dim appstad As String
    Dim stad As String
    Dim stadtyp As String
    Dim ENT As Single
    Dim AZOT As Single
    Dim MINX As Single
    Dim P As Single
    Dim CA As Single
     
    'ComboBox en cascade
     
    Private Sub UserForm_Initialize()
        Set Ws = Worksheets("Feuil2")
        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 ComboBox4_Change()
        Alim_Combo 5, ComboBox4.Value
    End Sub
     
    Private Sub ComboBox5_Change()
        Alim_Combo 6, ComboBox5.Value
    End Sub
    Private Sub ComboBox6_Change()
        Alim_Combo 7, ComboBox6.Value
    End Sub
     
    Private Sub ComboBox7_Change()
    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)
                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
       Obj.ListIndex = -1
    End Sub
     
    'Chercher la valeur d'une variable en fonction des valeurs de plusieurs variables
     
    Sub CommandButton1_Click()
     
    typalim = ComboBox1.Value
    modecon = ComboBox2.Value
    typf = ComboBox3.Value
    esp = ComboBox4.Value
    cycl = ComboBox5.Value
    appstad = ComboBox6.Value
    stad = ComboBox7.Value
     
     Dim Feuille As String
        Feuille = "Feuil2"
        If (Sheets(Feuille).AutoFilterMode = False) Then
            Sheets(Feuille).Cells.AutoFilter
        Else
            Sheets(Feuille).Cells.AutoFilter
            Sheets(Feuille).Cells.AutoFilter
    End If
     
    Feuille = "Feuil2"
    Sheets(Feuille).Cells.AutoFilter Field:=1, Criteria1:=ComboBox1.Value, Operator:=xlFilterValues
    Sheets(Feuille).Cells.AutoFilter Field:=2, Criteria1:=ComboBox2.Value, Operator:=xlFilterValues
    Sheets(Feuille).Cells.AutoFilter Field:=3, Criteria1:=ComboBox3.Value, Operator:=xlFilterValues
    Sheets(Feuille).Cells.AutoFilter Field:=4, Criteria1:=ComboBox4.Value, Operator:=xlFilterValues
    Sheets(Feuille).Cells.AutoFilter Field:=5, Criteria1:=ComboBox5.Value, Operator:=xlFilterValues
    Sheets(Feuille).Cells.AutoFilter Field:=6, Criteria1:=ComboBox6.Value, Operator:=xlFilterValues
    Sheets(Feuille).Cells.AutoFilter Field:=7, Criteria1:=ComboBox7.Value, Operator:=xlFilterValues
     
    'ENT = Sheets("Feuil2").Columns(12).SpecialCells(xlCellTypeVisible).End(xlDown).Value
     
    'Range("A1").Select
    'Selection.Value = ENT
    End Sub
    Private Sub CommandButton2_Click()
    Sheets("Feuil2").ShowAllData
    End Sub
    Je vous remercie infiniment!

  2. #2
    Membre actif
    Homme Profil pro
    Lycéen
    Inscrit en
    Février 2015
    Messages
    52
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Février 2015
    Messages : 52
    Par défaut
    Bonjour ,
    Après vérification le code marche bien j'ai un problème dans ma base de données !
    Merci beaucoup à vous tous !!

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

Discussions similaires

  1. [XL-2010] Code VBA - positionner au premier choix d'un filtre dans un TCD
    Par Ali.G dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 02/03/2012, 22h54
  2. Réponses: 4
    Dernier message: 21/06/2011, 09h10
  3. Réponses: 3
    Dernier message: 13/02/2009, 15h49
  4. Réponses: 4
    Dernier message: 12/10/2008, 20h14
  5. Erreur dans mon code php que j'arrive à voir
    Par babouba dans le forum Langage
    Réponses: 2
    Dernier message: 19/03/2007, 16h48

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