Returning multiple items from a listbox

K

Kevlar

I've done a lot of unsuccessful searching on this forum for this answer
I want to be able to select multiple items from a list box and retur
the results to a range.

I've found this code;

Private Sub CommandButton1_Click()

For x = 0 To ListBox1.ListCount - 1

If ListBox1.Selected(x) = True Then
ActiveCell.Value = UserForm1.ListBox1.List(x)

End If
Next x

End Sub

But it returns all selections to a single cell. What I need it to do i
return the first selection to A1, the second to A2, etc.

By the way, this site is awesome and has never let me down, pleas
don't fail me now! :
 
D

Dave Peterson

How about:

Private Sub CommandButton1_Click()
dim X as long
dim oRow as long

orow = 1
with worksheets("sheet1")
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
.cells(orow,"A").value = UserForm1.ListBox1.List(x)
orow = orow + 1
end if
Next x
end with
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top