Comment transférer les données d'une listbox vers la feuille ?

Résolu/Fermé
SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016 - 7 avril 2016 à 09:08
SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016 - 7 avril 2016 à 12:13
Bonjour,

Dans le cadre de mon travail, pour la création d'un "truc" automatisé :), j'ai pondu ça. Les valeurs rentrés dans les textbox se transfèrent bien vers la feuille, mais pas moyen de transférer la donnée sélectionné dans la listbox (Acceptée ou Refusée).

Private Sub CommandButtonOK_Click()
Range("V13") = TextBox9.Value
Range("N23") = TextBox2.Value
Range("N24") = TextBox3.Value
Range("X27") = TextBox4.Value
Range("X28") = TextBox5.Value
Range("X29") = TextBox6.Value
Range("N32") = TextBox7.Value
Range("X32") = TextBox8.Value
Unload Me
End Sub

Private Sub UserForm_Initialize()
ListBox1.List() = Range("BU20:BU22").Value
End Sub

Private Sub UserForm_Activate()
With Me
.StartUpPosition = 1
.Left = 100
.Top = 50
End With
End Sub



Une âme charitable peut-elle m'aider ? Je suis dessus depuis hier et je m'arrache les cheveux même si je n'en ai plus. J'ai ratissé Google (qui est mon ami), mais il m'a laissé tombé :'(

Merci d'avance.

A voir également:

1 réponse

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 743
Modifié par pijaku le 7/04/2016 à 11:25
Bonjour,

Quelque chose comme ça :
If listBox1.listIndex = -1 Then 
'Si aucune ligne n'est sélectionnée, la macro renverrait une erreur ICI
Else
    Range("A1") = ListBox1.List(ListBox1.ListIndex)
End If


Donc, en version plus courte :
If listBox1.listIndex > -1 Then Range("A1") = ListBox1.List(ListBox1.ListIndex)


Avant, j'arrivais jamais à finir mes phrases... mais maintenant je
0
SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016
7 avril 2016 à 12:00
Private Sub CommandButtonOK_Click()
Range("V13") = TextBox9.Value
Range("N23") = TextBox2.Value
Range("N24") = TextBox3.Value
Range("X27") = TextBox4.Value
Range("X28") = TextBox5.Value
Range("X29") = TextBox6.Value
Range("N32") = TextBox7.Value
Range("X32") = TextBox8.Value
Unload Me
End Sub


Private Sub UserForm_Initialize()
ListBox1.List() = Range("BU20:BU22").Value
If ListBox1.ListIndex > -1 Then Range("H62") = ListBox1.List(ListBox1.ListIndex)
End Sub

Private Sub UserForm_Activate()
With Me
.StartUpPosition = 1
.Left = 100
.Top = 50
End With
End Sub


Comme cela ?
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 743 > SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016
7 avril 2016 à 12:04
Ben non, pas à l'initialisation de l'userform allons...

Tu dis :
Les valeurs rentrés dans les textbox se transfèrent bien vers la feuille, mais pas moyen de transférer la donnée sélectionné dans la listbox

Qu'elle procédure utilises tu pour que les valeurs saisies dans tes textbox se transfèrent sur la feuille?
CommandButtonOK_Click

Ok?
Donc c'est dans le code de ton bouton :
Private Sub CommandButtonOK_Click()
    Range("V13") = TextBox9.Value
    Range("N23") = TextBox2.Value
    Range("N24") = TextBox3.Value
    Range("X27") = TextBox4.Value
    Range("X28") = TextBox5.Value
    Range("X29") = TextBox6.Value
    Range("N32") = TextBox7.Value
    Range("X32") = TextBox8.Value
    If ListBox1.ListIndex > -1 Then Range("H62") = ListBox1.List(ListBox1.ListIndex)
    Unload Me
End Sub
0
SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016
Modifié par SOMUM le 7/04/2016 à 12:08
Tu mérite un bisou :)

Je précise que je suis totalement newbee de Excel. mais qu'au final j'ai (et les utilisateurs du forum aussi) réussi à faire un truc bien chiadé :)
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 743 > SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016
7 avril 2016 à 12:09
Tant mieux pour toi.
A+
0
SOMUM Messages postés 28 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 1 août 2016
7 avril 2016 à 12:13
Merci beaucoup !
0