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

Résolu
SOMUM Messages postés 28 Statut Membre -  
SOMUM Messages postés 28 Statut Membre -
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.

1 réponse

  1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
     
    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
    1. SOMUM Messages postés 28 Statut Membre
       
      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
      1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773 > SOMUM Messages postés 28 Statut Membre
         
        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
    2. SOMUM Messages postés 28 Statut Membre
       
      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
      1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773 > SOMUM Messages postés 28 Statut Membre
         
        Tant mieux pour toi.
        A+
        0
    3. SOMUM Messages postés 28 Statut Membre
       
      Merci beaucoup !
      0