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 :

Selection ligne dans listbox


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
    Webmaster
    Inscrit en
    Juin 2015
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2015
    Messages : 20
    Par défaut Selection ligne dans listbox
    Bonjour a tous
    encore un petit coup de main
    meme si mon code n’est pas ortodoxe car j’ai encore beaucoup a apprendre
    je me debrouille avec les forum et les different exemple pour fonctionne mon programme
    mais la je ne touve pas ou je suis passer a cote de quelque chose
    j’ai une listbox avec 9 criteres de recherche et 108 colonnes
    je n’arrive pas en selectionnant une ligne et en cliquant sur le bouton visu devis a recuperer toutes les donnees de cette ligne
    dans la feuille resultat
    je copie toujours la premiere ligne de ma listbox
    un peu d’aide serais bienvenu et surtout quelques explications sur mon erreur
    merci d’avance a tous ceux qui se pencheront sur mon probleme

    ps ci joint mon fichier
    Fichiers attachés Fichiers attachés

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Octobre 2012
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2012
    Messages : 199
    Par défaut
    Bonjour,

    A tester


    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
     
    Private Sub CommandButton1_Click()
     
     
    Dim selecteditems As String
    Dim compt As Integer
     
    For I = 0 To ListBox1.ListCount - 1
     
        If ListBox1.Selected(I) = True Then
            selecteditems = selecteditems & ListBox1.List(I)
            compt = I 'LIGNE A AJOUTER
            Exit For 'LIGNE A AJOUTER
        End If
     
    Next I
     
     
    If selecteditems = "" Then
        MsgBox "pas de Devis selectioner"
    Else
    Dim Ligne As String
      Dim LigneExcel1 As Integer
      'Dim compt As Integer 'A DEPLACER EN DEBUT DE CODE
     
        LigneExcel1 = 2
     
      With ActiveWorkbook.Worksheets("resultat")
     .Cells(LigneExcel1, 1) = ListBox1.List(compt)
     .Cells(LigneExcel1, 2) = ListBox1.List(compt, 1)
     .Cells(LigneExcel1, 3) = ListBox1.List(compt, 2)
     .Cells(LigneExcel1, 4) = ListBox1.List(compt, 3)
     .Cells(LigneExcel1, 5) = ListBox1.List(compt, 4)
     .Cells(LigneExcel1, 6) = ListBox1.List(compt, 5)
     .Cells(LigneExcel1, 7) = ListBox1.List(compt, 6)
     .Cells(LigneExcel1, 8) = ListBox1.List(compt, 7)
     .Cells(LigneExcel1, 9) = ListBox1.List(compt, 8)
     .Cells(LigneExcel1, 10) = ListBox1.List(compt, 9)
     .Cells(LigneExcel1, 11) = ListBox1.List(compt, 10)
     .Cells(LigneExcel1, 12) = ListBox1.List(compt, 11)
     .Cells(LigneExcel1, 13) = ListBox1.List(compt, 12)
     .Cells(LigneExcel1, 14) = ListBox1.List(compt, 13)
     .Cells(LigneExcel1, 15) = ListBox1.List(compt, 14)
     .Cells(LigneExcel1, 16) = ListBox1.List(compt, 15)
     .Cells(LigneExcel1, 17) = ListBox1.List(compt, 16)
     .Cells(LigneExcel1, 18) = ListBox1.List(compt, 17)
     .Cells(LigneExcel1, 19) = ListBox1.List(compt, 18)
     .Cells(LigneExcel1, 20) = ListBox1.List(compt, 19)
     .Cells(LigneExcel1, 21) = ListBox1.List(compt, 20)
     .Cells(LigneExcel1, 22) = ListBox1.List(compt, 21)
     .Cells(LigneExcel1, 23) = ListBox1.List(compt, 22)
     .Cells(LigneExcel1, 24) = ListBox1.List(compt, 23)
     .Cells(LigneExcel1, 25) = ListBox1.List(compt, 24)
     .Cells(LigneExcel1, 26) = ListBox1.List(compt, 25)
     .Cells(LigneExcel1, 27) = ListBox1.List(compt, 26)
     .Cells(LigneExcel1, 28) = ListBox1.List(compt, 27)
     .Cells(LigneExcel1, 29) = ListBox1.List(compt, 28)
     .Cells(LigneExcel1, 30) = ListBox1.List(compt, 29)
     .Cells(LigneExcel1, 31) = ListBox1.List(compt, 30)
     .Cells(LigneExcel1, 32) = ListBox1.List(compt, 31)
     .Cells(LigneExcel1, 33) = ListBox1.List(compt, 32)
     .Cells(LigneExcel1, 34) = ListBox1.List(compt, 33)
     .Cells(LigneExcel1, 35) = ListBox1.List(compt, 34)
     .Cells(LigneExcel1, 36) = ListBox1.List(compt, 35)
     .Cells(LigneExcel1, 37) = ListBox1.List(compt, 36)
     .Cells(LigneExcel1, 38) = ListBox1.List(compt, 37)
     .Cells(LigneExcel1, 39) = ListBox1.List(compt, 38)
     .Cells(LigneExcel1, 40) = ListBox1.List(compt, 39)
     .Cells(LigneExcel1, 41) = ListBox1.List(compt, 40)
     .Cells(LigneExcel1, 42) = ListBox1.List(compt, 41)
     .Cells(LigneExcel1, 43) = ListBox1.List(compt, 42)
     .Cells(LigneExcel1, 44) = ListBox1.List(compt, 43)
     .Cells(LigneExcel1, 45) = ListBox1.List(compt, 44)
     .Cells(LigneExcel1, 46) = ListBox1.List(compt, 45)
     .Cells(LigneExcel1, 47) = ListBox1.List(compt, 46)
     .Cells(LigneExcel1, 48) = ListBox1.List(compt, 47)
     .Cells(LigneExcel1, 49) = ListBox1.List(compt, 48)
     .Cells(LigneExcel1, 50) = ListBox1.List(compt, 49)
     .Cells(LigneExcel1, 51) = ListBox1.List(compt, 50)
     .Cells(LigneExcel1, 52) = ListBox1.List(compt, 51)
     .Cells(LigneExcel1, 53) = ListBox1.List(compt, 52)
     .Cells(LigneExcel1, 54) = ListBox1.List(compt, 53)
     .Cells(LigneExcel1, 55) = ListBox1.List(compt, 54)
     .Cells(LigneExcel1, 56) = ListBox1.List(compt, 55)
     .Cells(LigneExcel1, 57) = ListBox1.List(compt, 56)
     .Cells(LigneExcel1, 58) = ListBox1.List(compt, 56)
     .Cells(LigneExcel1, 59) = ListBox1.List(compt, 58)
     .Cells(LigneExcel1, 60) = ListBox1.List(compt, 59)
     .Cells(LigneExcel1, 61) = ListBox1.List(compt, 60)
     .Cells(LigneExcel1, 62) = ListBox1.List(compt, 61)
     .Cells(LigneExcel1, 63) = ListBox1.List(compt, 62)
     .Cells(LigneExcel1, 64) = ListBox1.List(compt, 63)
     .Cells(LigneExcel1, 65) = ListBox1.List(compt, 64)
     .Cells(LigneExcel1, 66) = ListBox1.List(compt, 65)
     .Cells(LigneExcel1, 67) = ListBox1.List(compt, 66)
     .Cells(LigneExcel1, 68) = ListBox1.List(compt, 67)
     .Cells(LigneExcel1, 69) = ListBox1.List(compt, 68)
     .Cells(LigneExcel1, 70) = ListBox1.List(compt, 69)
     .Cells(LigneExcel1, 71) = ListBox1.List(compt, 70)
     .Cells(LigneExcel1, 72) = ListBox1.List(compt, 71)
     .Cells(LigneExcel1, 73) = ListBox1.List(compt, 72)
     .Cells(LigneExcel1, 74) = ListBox1.List(compt, 73)
     .Cells(LigneExcel1, 75) = ListBox1.List(compt, 74)
     .Cells(LigneExcel1, 76) = ListBox1.List(compt, 75)
     .Cells(LigneExcel1, 77) = ListBox1.List(compt, 76)
     .Cells(LigneExcel1, 78) = ListBox1.List(compt, 77)
     .Cells(LigneExcel1, 79) = ListBox1.List(compt, 78)
     .Cells(LigneExcel1, 80) = ListBox1.List(compt, 79)
     .Cells(LigneExcel1, 81) = ListBox1.List(compt, 80)
     .Cells(LigneExcel1, 82) = ListBox1.List(compt, 81)
     .Cells(LigneExcel1, 83) = ListBox1.List(compt, 82)
     .Cells(LigneExcel1, 84) = ListBox1.List(compt, 83)
     .Cells(LigneExcel1, 85) = ListBox1.List(compt, 84)
     .Cells(LigneExcel1, 86) = ListBox1.List(compt, 85)
     .Cells(LigneExcel1, 87) = ListBox1.List(compt, 86)
     .Cells(LigneExcel1, 88) = ListBox1.List(compt, 87)
     .Cells(LigneExcel1, 89) = ListBox1.List(compt, 88)
     .Cells(LigneExcel1, 90) = ListBox1.List(compt, 89)
     .Cells(LigneExcel1, 91) = ListBox1.List(compt, 90)
     .Cells(LigneExcel1, 92) = ListBox1.List(compt, 91)
     .Cells(LigneExcel1, 93) = ListBox1.List(compt, 92)
     .Cells(LigneExcel1, 94) = ListBox1.List(compt, 93)
     .Cells(LigneExcel1, 95) = ListBox1.List(compt, 94)
     .Cells(LigneExcel1, 96) = ListBox1.List(compt, 95)
     .Cells(LigneExcel1, 97) = ListBox1.List(compt, 96)
     .Cells(LigneExcel1, 98) = ListBox1.List(compt, 97)
     .Cells(LigneExcel1, 99) = ListBox1.List(compt, 98)
     .Cells(LigneExcel1, 100) = ListBox1.List(compt, 99)
     .Cells(LigneExcel1, 101) = ListBox1.List(compt, 100)
     .Cells(LigneExcel1, 102) = ListBox1.List(compt, 101)
     .Cells(LigneExcel1, 103) = ListBox1.List(compt, 102)
     .Cells(LigneExcel1, 104) = ListBox1.List(compt, 103)
     .Cells(LigneExcel1, 105) = ListBox1.List(compt, 104)
     .Cells(LigneExcel1, 106) = ListBox1.List(compt, 105)
     .Cells(LigneExcel1, 107) = ListBox1.List(compt, 106)
     .Cells(LigneExcel1, 108) = ListBox1.List(compt, 107)
     LigneExcel = LigneExcel + 1
      End With
     
     
     
    End If
    End Sub
    Cordialement,

  3. #3
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    3 453
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 3 453
    Par défaut
    Bonjour,

    Je verrai bien le code comme ça :
    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
     
    Private Sub CommandButton1_Click()
     
        Dim I As Integer
     
        If ListBox1.ListIndex = -1 Then
     
            MsgBox "Pas de Devis selectionné !"
     
        Else
     
            With ActiveWorkbook.Worksheets("resultat")
     
                For I = 1 To 108
     
                    .Cells(2, I).Value = ListBox1.List(ListBox1.ListIndex, I - 1)
     
                Next I
     
            End With
     
        End If
     
    End Sub
    Hervé.

  4. #4
    Membre actif
    Homme Profil pro
    Webmaster
    Inscrit en
    Juin 2015
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Webmaster
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2015
    Messages : 20
    Par défaut
    BONJOUR A TOUS LES DEUX
    MERCI POUR VOS REPONSES RAPIDE ET TOUJOURS AUSSI EFFICACE
    APRES TEST LES DEUX CODE FONCTIONNE
    MAIS CELUI DE THEZE ET BEAUCOUP PLUS LEGER

    ENCORE UN GRAND MERCI ET CONTINUEZ COMME CA

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

Discussions similaires

  1. [XL-2007] Hauteur de ligne dans listbox
    Par eliot.raymond dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 02/07/2010, 16h22
  2. nombre de lignes dans ListBox
    Par dz_robotix dans le forum C++Builder
    Réponses: 7
    Dernier message: 10/06/2009, 22h38
  3. selectionner une autre ligne dans listbox
    Par nicht dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 16/04/2009, 12h29
  4. Selection multiple dans Listbox
    Par Pierre67 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 03/12/2008, 17h48
  5. [VB6]Comment inserer plusieurs infos sur meme ligne dans listbox ?
    Par angelevil dans le forum VB 6 et antérieur
    Réponses: 25
    Dernier message: 31/05/2006, 19h03

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