Excel VBA - RowSource for ListBox

B

Bhuktar S

The list is available in Sheet2, I want to put the selected in Sheet1.
How do I write in UserFormInitialize?
I tried
ListBox1.RowSource=WorkSheets("Sheet2).Range("A1:A20")
But does not work.
Secondly, I need to put the multiple selected items from the ListBox
to sheet1. How do I do that
 
B

Bob Flanagan

I have found it is easier just to add the entries to the list box:

Dim cell As Range
With UserForm1.ListBox1
.Clear
For Each cell In Worksheets("Sheet2").Range("A1:A20")
.AddItem cell.Value2
Next
End With

If you set the listbox to multi select then

Set cell = Worksheets("sheet1").Cells(1, 1)
Dim I As Integer
With UserForm1.ListBox1
For I = 0 To .ListCount - 1
If .Selected(I) Then
cell.Value2 = .List(I)
Set cell = cell.Offset(1, 0)
End If
Next
End With

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 

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