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

Résolu
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. Modérateur
    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. 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
    2. Modérateur
      @SOMUMBen 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
    3. 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
    4. Modérateur
      @SOMUMTant mieux pour toi.
      A+
      0
    5. Merci beaucoup !
      0