How to transfer data from a listbox to the sheet?
Solved
SOMUM
Posted messages
28
Status
Member
-
SOMUM Posted messages 28 Status Member -
SOMUM Posted messages 28 Status Member -
Hello,
As part of my work, for the creation of an automated "thing" :), I came up with this. The values entered in the textboxes transfer well to the sheet, but I can't manage to transfer the selected data from the listbox (Accepted or Refused).
Is there a kind soul who can help me? I've been working on this since yesterday and I'm pulling my hair out even though I don't have much left. I've searched Google (who is my friend), but it let me down :'(
Thank you in advance.
Configuration: Windows 7 / Chrome 49.0.2623.110 / Excel 2010
As part of my work, for the creation of an automated "thing" :), I came up with this. The values entered in the textboxes transfer well to the sheet, but I can't manage to transfer the selected data from the listbox (Accepted or Refused).
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
Is there a kind soul who can help me? I've been working on this since yesterday and I'm pulling my hair out even though I don't have much left. I've searched Google (who is my friend), but it let me down :'(
Thank you in advance.
Configuration: Windows 7 / Chrome 49.0.2623.110 / Excel 2010
1 answer
-
Hello,
Something like this:If listBox1.listIndex = -1 Then 'If no line is selected, the macro would return an error HERE Else Range("A1") = ListBox1.List(ListBox1.ListIndex) End If
So, in a shorter version:If listBox1.listIndex > -1 Then Range("A1") = ListBox1.List(ListBox1.ListIndex)
Before, I never managed to finish my sentences... but now I-
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
Yes, that’s it?- Well no, not at the initialization of the userform come on...
You said:
The values entered in the textboxes transfer correctly to the sheet, but there’s no way to transfer the selected data from the listbox
What procedure are you using for the values entered in your textboxes to transfer to the sheet?
CommandButtonOK_Click
Okay?
So it’s in the code of your button: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
-
-
-