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 :

Probleme listbox avec condition


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2019
    Messages : 5
    Par défaut Probleme listbox avec condition
    Bonjour à tous !

    J'ai un soucis d'affichage de ma listbox, j'aimerais pouvoir afficher les données de la feuille excel " Appel1" dans une listbox.
    Cet affichage de la listbox doit se faire en fonction des conditions que je rentre dans la feuille "acceuil" a travers l'userform 1 en cliquant sur le bouton "Soumettre"

    Le probleme c'est qu'avec le code ci dessous l'affichage conditionnel ne se fait pas .. Auriez vous une solution à mon probleme ?

    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
    Dim i As Integer, l as long
    Dim Tableau(), x as long
     
    With WorkSheets("Appel1")
    l = .Range("d65536").End(xlUp).Row + 1
    For i = 2 To l
          If Sheets("Acceuil").Range("B2").Value = "PME" And Sheets("Appel1").Cells(i, 1).Value = "PME" Then
                x=x+1
                redim Tableau(1 to 12 , 1 to x)
               Tableau(1 , x) = .Cells(i, 1).Value
               Tableau(2 , x) = .Cells(i, 2).Value
               Tableau(3 , x) = .Cells(i, 4).Value
               Tableau(4 , x) = .Cells(i, 7).Value
               Tableau(5, x) = .Cells(i, 5).Value
               Tableau(6 , x) = .Cells(i, 6).Value
               Tableau(7 , x) = .Cells(i, 8).Value
               Tableau(8 , x) = .Cells(i, 9).Value
               Tableau(9 , x) = .Cells(i, 10).Value
               Tableau(10 , x) = .Cells(i, 11).Value
               Tableau(11 , x) = .Cells(i, 12).Value
               Tableau(12 , x) = .Cells(i, 13).Value
        End If
    Next i
    End With
     
    Listbox1.list =application.transpose( Tableau)
    ' ou a priori
    'Listbox1.column= Tableau
    Merci d'avance !
    Fichiers attachés Fichiers attachés

  2. #2
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    bonjour
    1/ merci de baliser ton code pour qu'il soit lisible (entre #)
    2/ tentative de réponse
    * inutile d'ajouter 1 à la dernière ligne non vide
    * déclarer la valeur de x en dehors du boucle et après la fin de if ajouter un 1 (x=x+1)
    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
    Dim i As Integer, l As Long
    Dim Tableau(), x As Long
     
    With Worksheets("Appel1")
    l = .Range("g65536").End(xlUp).Row
    x = 1
    For i = 2 To l
          If Sheets("Acceuil").Range("B2").Value = "PME" And Sheets("Appel1").Cells(i, 1).Value = "PME" Then
     
                ReDim Tableau(1 To 12, 1 To x)
               Tableau(1, x) = .Cells(i, 1).Value
               Tableau(2, x) = .Cells(i, 2).Value
               Tableau(3, x) = .Cells(i, 4).Value
               Tableau(4, x) = .Cells(i, 7).Value
               Tableau(5, x) = .Cells(i, 5).Value
               Tableau(6, x) = .Cells(i, 6).Value
               Tableau(7, x) = .Cells(i, 8).Value
               Tableau(8, x) = .Cells(i, 9).Value
               Tableau(9, x) = .Cells(i, 10).Value
               Tableau(10, x) = .Cells(i, 11).Value
               Tableau(11, x) = .Cells(i, 12).Value
               Tableau(12, x) = .Cells(i, 13).Value
        End If
         x = x + 1
    Next i
    End With
     
    ListBox1.List = Application.Transpose(Tableau)

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2019
    Messages : 5
    Par défaut
    Re bonjour,

    Merci pour la synthaxe !

    Voici en Photo ce que j'obtiens .. hors ce n'est pas la seule ligne présentant "PME" comme condition ... j'en ai 2 ou 3 pour le test mais ça ne fonctionne pas..

    le code semble bon

    J'ai essayé de modifié
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    l = .Range("g65536").End(xlUp).Row
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    l = .Range("m65536").End(xlUp).Row
    et ça modifie mais en ne mettant les colonnes de la première ligne, tout en ligne et pas en colonne..

    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
    Dim i As Integer, l As Long
    Dim Tableau(), x As Long
     
    With Worksheets("Appel1")
    l = .Range("g65536").End(xlUp).Row
    x = 1
    For i = 2 To l
          If Sheets("Acceuil").Range("B2").Value = "PME" And Sheets("Appel1").Cells(i, 1).Value = "PME" Then
     
                ReDim Tableau(1 To 12, 1 To x)
               Tableau(1, x) = .Cells(i, 1).Value
               Tableau(2, x) = .Cells(i, 2).Value
               Tableau(3, x) = .Cells(i, 4).Value
               Tableau(4, x) = .Cells(i, 7).Value
               Tableau(5, x) = .Cells(i, 5).Value
               Tableau(6, x) = .Cells(i, 6).Value
               Tableau(7, x) = .Cells(i, 8).Value
               Tableau(8, x) = .Cells(i, 9).Value
               Tableau(9, x) = .Cells(i, 10).Value
               Tableau(10, x) = .Cells(i, 11).Value
               Tableau(11, x) = .Cells(i, 12).Value
               Tableau(12, x) = .Cells(i, 13).Value
        End If
         x = x + 1
    Next i
    End With
     
    ListBox1.List = Application.Transpose(Tableau)
    Images attachées Images attachées  
    Fichiers attachés Fichiers attachés

  4. #4
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    re bonjour
    je suis nul en tableau et pour tel cas je fais avec :
    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
    Dim i As Integer, l As Long
    Dim x As Byte
     
    With Worksheets("Appel1")
    l = .Range("g65536").End(xlUp).Row
     
    x = 0
    For i = 2 To l
          If Sheets("Acceuil").Range("B2").Value = "PME" And Sheets("Appel1").Cells(i, 1).Value = "PME" Then
     
     
     On Error Resume Next
        UserForm2.ListBox1.ColumnCount = 12
        UserForm2.ListBox1.ColumnWidths = "30;30;30;30;30;30;30;30;30;30;30;30"
        UserForm2.ListBox1.AddItem
        UserForm2.ListBox1.Column(0, x) = .Cells(i, 1).Value
        UserForm2.ListBox1.Column(1, x) = .Cells(i, 2).Value
        UserForm2.ListBox1.Column(2, x) = .Cells(i, 3).Value
        UserForm2.ListBox1.Column(3, x) = .Cells(i, 4).Value
        UserForm2.ListBox1.Column(4, x) = .Cells(i, 5).Value
        UserForm2.ListBox1.Column(5, x) = .Cells(i, 6).Value
        UserForm2.ListBox1.Column(6, x) = .Cells(i, 7).Value
        UserForm2.ListBox1.Column(7, x) = .Cells(i, 8).Value
        UserForm2.ListBox1.Column(8, x) = .Cells(i, 9).Value
        UserForm2.ListBox1.Column(9, x) = .Cells(i, 10).Value
        UserForm2.ListBox1.Column(10, x) = .Cells(i, 11).Value
        UserForm2.ListBox1.Column(11, x) = .Cells(i, 12).Value
     
       x = x + 1
        End If
     
         Next i
     
     
     
     End With

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2019
    Messages : 5
    Par défaut
    Oui j'ai utilisé aussi le AddItem mais cependant je fais face a plus de 10 colonnes dans mon tableau donc plus de 10 colonnes sur la listbox hors j'ai cette erreur du à la limite de additem
    et c'est pour cela que j'étais parti sur l'autre solution ..
    Images attachées Images attachées  

Discussions similaires

  1. Recherche intuitive textBox et affichage dans listbox avec condition
    Par Osaka2017 dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 25/04/2019, 10h27
  2. [XL-2007] Problème source Listbox avec condition
    Par ben59 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 17/11/2010, 13h44
  3. Réponses: 2
    Dernier message: 03/03/2008, 15h06
  4. probleme virgule dans une ListBox avec stringht
    Par yomane 51 dans le forum Delphi
    Réponses: 1
    Dernier message: 10/01/2007, 17h47
  5. Réponses: 4
    Dernier message: 09/05/2006, 08h55

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