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 :

Problème de listbox


Sujet :

Macros et VBA Excel

  1. #1
    Membre confirmé
    Homme Profil pro
    Educateur Animateur
    Inscrit en
    Février 2013
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur Animateur
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2013
    Messages : 132
    Par défaut Problème de listbox
    Bonjour,

    J'ai un bug sur une listbox...

    Cette listbox affiche ou non des infos en fonction d'un critère particulier. Il peut donc y avoir des infos affichées (celà fonctionne) ou bien aucune info affichée...
    c'est dans ce deuxième cas que j'ai un souci puisque la listbox tri automatiquement les infos affichées dans l'ordre alphabétique... mais si il n'y a pas d'infos à afficher le programme s'arrête car il n'arrive pas à trier...

    voici le code

    Avez-vous une idée !?

    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
    Private Sub CommandButton3_Click()
      Dim Plage As Range, Est, Add As String, vLi As Integer, Vcol As Byte
      Dim i As Integer
      Dim temp
      Dim Ok As Boolean
     
      With ListBox1
        .Clear
        .ColumnCount = 6
        .ColumnWidths = "120;90;20;255;80;60"
        Set Plage = Range("H2:H" & [H65000].End(xlUp).Row)
        Set Est = Plage.Find(False)
        If Not Est Is Nothing Then
          Add = Est.Address
          Do
            .AddItem Cells(Est.Row, 1)
            For Vcol = 2 To 6
              .List(vLi, Vcol - 1) = Cells(Est.Row, Vcol)
            Next
            vLi = vLi + 1
            Set Est = Plage.FindNext(Est)
          Loop While Not Est Is Nothing And Est.Address <> Add
        End If
        TextBox1 = .ListCount
      End With
     
     
    'pour trier l'affichage
     Dim Lig
     Dim Col
     Dim clé() As String, index() As Long, a(), b()
     a = Me.ListBox1.List
     ReDim b(LBound(a) To UBound(a), LBound(a, 2) To UBound(a, 2))
     ReDim clé(LBound(a) To UBound(a, 1))
     ReDim index(LBound(a) To UBound(a, 1))
     For i = LBound(a) To UBound(a, 1)
        clé(i) = a(i, 0) & a(i, 1): index(i) = i
      Next i
      Call Tri(clé(), index(), LBound(a), UBound(clé))
      For Lig = LBound(clé) To UBound(clé)
         For Col = LBound(a, 2) To UBound(a, 2): b(Lig, Col) = a(index(Lig), Col): Next Col
      Next Lig
      Me.ListBox1.List = b
     
      End Sub

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    652
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2009
    Messages : 652
    Par défaut
    Bonjour,

    Peut être en ajoutant l'instruction signalée par des ###

    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
    Private Sub CommandButton3_Click()
      Dim Plage As Range, Est, Add As String, vLi As Integer, Vcol As Byte
      Dim i As Integer
      Dim temp
      Dim Ok As Boolean
     
      With ListBox1
        .Clear
        .ColumnCount = 6
        .ColumnWidths = "120;90;20;255;80;60"
        Set Plage = Range("H2:H" & [H65000].End(xlUp).Row)
        Set Est = Plage.Find(False)
        If Not Est Is Nothing Then
          Add = Est.Address
          Do
            .AddItem Cells(Est.Row, 1)
            For Vcol = 2 To 6
              .List(vLi, Vcol - 1) = Cells(Est.Row, Vcol)
            Next
            vLi = vLi + 1
            Set Est = Plage.FindNext(Est)
          Loop While Not Est Is Nothing And Est.Address <> Add
        End If
        TextBox1 = .ListCount
      End With
     
     
    'pour trier l'affichage
     Dim Lig
     Dim Col
     Dim clé() As String, index() As Long, a(), b()
     
    If Me.ListBox1.ListCount = 0 Then Exit Sub   '###
     
     a = Me.ListBox1.List
     ReDim b(LBound(a) To UBound(a), LBound(a, 2) To UBound(a, 2))
     ReDim clé(LBound(a) To UBound(a, 1))
     ReDim index(LBound(a) To UBound(a, 1))
     For i = LBound(a) To UBound(a, 1)
        clé(i) = a(i, 0) & a(i, 1): index(i) = i
      Next i
      Call Tri(clé(), index(), LBound(a), UBound(clé))
      For Lig = LBound(clé) To UBound(clé)
         For Col = LBound(a, 2) To UBound(a, 2): b(Lig, Col) = a(index(Lig), Col): Next Col
      Next Lig
      Me.ListBox1.List = b
     
      End Sub

  3. #3
    Membre confirmé
    Homme Profil pro
    Educateur Animateur
    Inscrit en
    Février 2013
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Educateur Animateur
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2013
    Messages : 132
    Par défaut
    ça fonctionne c'est super... j'avais essayé cette solution mais j'avais oulié .Listcount


    Merci pour ta réponse

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

Discussions similaires

  1. [VBA-E] Problème de ListBox
    Par sat478 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 20/06/2007, 10h42
  2. Problème de listbox
    Par lulux80 dans le forum VB 6 et antérieur
    Réponses: 33
    Dernier message: 28/02/2007, 16h45
  3. [c#]Problème chargement ListBox
    Par Filippo dans le forum ASP.NET
    Réponses: 1
    Dernier message: 05/01/2007, 18h30
  4. [ACCESS 2000] Problème de listBox
    Par noemieze dans le forum Access
    Réponses: 3
    Dernier message: 27/06/2006, 08h58
  5. [débutant] Problème de listBox
    Par Anthony17 dans le forum Débuter
    Réponses: 6
    Dernier message: 11/05/2006, 10h05

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