Source d'une Listbox

Résolu/Fermé
DGVDR Messages postés 158 Date d'inscription vendredi 10 août 2012 Statut Membre Dernière intervention 20 juillet 2015 - Modifié par DGVDR le 11/12/2013 à 10:51
DGVDR Messages postés 158 Date d'inscription vendredi 10 août 2012 Statut Membre Dernière intervention 20 juillet 2015 - 11 déc. 2013 à 14:30
Bonjour,

Etant un débutant, je rencontre des problèmes de débutant...

Dans mon userform gestionstock,
Je souhaite incrémenter une listbox appelée "Plagemachine"
Mes données se trouvent dans l'onglet "Préventif", dans la colonne X


Private Sub gestionstock_Initialize()
'si la dernière ligne est supérieure à 256 déclarer i et x en Integer

Dim i As Byte, x As Byte
i = Sheets("Préventif").Range("x65536").End(xlUp).Row

For x = 1 To i
With Plagemachine
.AddItem Sheets("Préventif").Range("x" & x)
End With
Next x
End Sub

Rien n'apparait dans ma listbox...

Merci,

DGVDR

4 réponses

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 754
11 déc. 2013 à 11:50
Bonjour,

Essayez peut être comme ceci :

Private Sub gestionstock_Initialize()
'si la dernière ligne est supérieure à 256 déclarer i et x en Integer
Dim i As Byte, x As Byte

With Sheets("Préventif")
    i = .Range("x65536").End(xlUp).Row
    For x = 1 To i
        Plagemachine.AddItem .Range("X" & x)
    Next x
End With
End Sub

0
DGVDR Messages postés 158 Date d'inscription vendredi 10 août 2012 Statut Membre Dernière intervention 20 juillet 2015
11 déc. 2013 à 12:07
Bonjour pijaku,

Pas mieux...

Ca reste vierge...!
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 754
Modifié par pijaku le 11/12/2013 à 12:19
Essaie avec des MsgBox en "arrêt", comme ceci :

Private Sub gestionstock_Initialize()
'si la dernière ligne est supérieure à 256 déclarer i et x en Integer
Dim i As Byte, x As Byte

With Sheets("Préventif")
    i = .Range("x65536").End(xlUp).Row
    MsgBox i
    For x = 1 To i
        MsgBox .Range("X" & x).Value
        Plagemachine.AddItem .Range("X" & x).Value
    Next x
End With
End Sub


Tu verras comme cela ce qui cloche...
0
Polux31 Messages postés 6917 Date d'inscription mardi 25 septembre 2007 Statut Membre Dernière intervention 1 novembre 2016 1 204
Modifié par Polux31 le 11/12/2013 à 12:27
Bonjour DGCDR, Bonjour Pijaku,

Pourquoi déclarer i et x en byte alors que l'on a :
i = .Range("x65536").End(xlUp).Row

Autant déclarer i et x en Long.

Le code de Pijaku fonctionne correctement.


«Ce que l'on conçoit bien s'énonce clairement, Et les mots pour le dire arrivent aisément.»
Nicolas Boileau
0
DGVDR Messages postés 158 Date d'inscription vendredi 10 août 2012 Statut Membre Dernière intervention 20 juillet 2015
11 déc. 2013 à 14:17
De mon coté, ça ne fonctionne pas...

Ci-dessous mon fichier.

https://www.cjoint.com/c/CLloqTfRJdy

Si vous voyez l'erreur.

Mon code VBA est "unzo"

Merci à vous deux,

DGVDR
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 754
Modifié par pijaku le 11/12/2013 à 14:21
Ben oui.......
N'utilise pas Private Sub gestionstock_initialise() mais :

Private Sub UserForm_Initialize()
'si la dernière ligne est supérieure à 256 déclarer i et x en Integer
Dim i As Long, x As Long

With Sheets("Préventif")
    i = .Range("X65536").End(xlUp).Row
    For x = 1 To i        
        Plagemachine.AddItem .Range("X" & x).Value
    Next x
End With
End Sub
0
DGVDR Messages postés 158 Date d'inscription vendredi 10 août 2012 Statut Membre Dernière intervention 20 juillet 2015
11 déc. 2013 à 14:24
Entendu, merci.

Cependant ici je ne définis "Plagemachine" à aucun moment ?

DGVDR
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 754
11 déc. 2013 à 14:28
Oula.... C'est quoi cette question?
Tu veux dire quoi??? Tu entends quoi par "définir plagemachine"?
0
DGVDR Messages postés 158 Date d'inscription vendredi 10 août 2012 Statut Membre Dernière intervention 20 juillet 2015
11 déc. 2013 à 14:30
C'est bon, ça fonctionne.

J'avais zappé que "Plagemachine" était ma ListBox.

Merci beaucoup.

DGVDR
0