Multiple Selection ListBox in Userform Data Output

Johndinho

Board Regular
Joined
Mar 21, 2013
Messages
90
Hi,

I have a listbox in a userform enabled to allow the user to make multiple selections.

Based on the user's selection; I want those individual values entered to a range in my sheet.

I have got as far as...(Shamelessly copied from this site)

Code:
For i = 0 To ListBox1.ListCount - 1
   If ListBox1.Selected(i) Then
'     ** Your code goes here ***
   End If
Next i
[CODE]

But what is the code to say X1 = first value, X2 = second value etc..?

Thanks,

Johndinho
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If by X1 you mean cell X1 then
Code:
For i = 0 To ListBox1.ListCount - 1
   If ListBox1.Selected(i) Then
      Range("X" & i + 1).Value = ListBox.list(i)
   End If
Next i
 
Upvote 0
Thanks Fluff and yes, X1 is cell X1

When I run your code I get the error message object required


Code:
Private Sub CommandButton1_Click()
    For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
    Range("X" & i + 1).Value = ListBox.List(i)
    End If
Next i
End Sub[CODE]

Any ideas?
 
Upvote 0
Here is a example of a script I use
Adds values selected in listbox to column (O) of active sheet.

Code:
Private Sub CommandButton8_Click()
'Add listbox1 values to column O
Dim i As Long
Dim b As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "O").End(xlUp).Row
For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) = True Then
        Cells(lastrow + 1, "O") = ListBox1.List(i)
        lastrow = lastrow + 1
        
    End If
Next
For b = 0 To ListBox1.ListCount - 1
'Unselect listbox values
        If ListBox1.Selected(b) = True Then ListBox1.Selected(b) = False
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top