Copy selected items from a listbox in a user form to another worksheet

K

KimberlyC

Hi

I rec'd some help today from the newsgroup (Michael J. Malinsky)... I posted
a question back..but after reading it realized I might not have explained it
very well.

He gave me this code below (that works great) that populates a listbox in a
userform with data in cells starting with D9 to M11 on the active
worksheet. The listbox is populated with multiple cells for each item
....for example .. (d9,d10,and d11 make up one item in the list box...and e9,
e10, and e11 make up the next item in the listbox and so on unitl you each
m9, m10, and m11)

Sub UserForm_Initialize()

Dim x As Integer

ListBox1.ColumnCount = 3

For x = 4 To 13
ListBox1.AddItem (ActiveSheet.Cells(9, x).Value)
ListBox1.List(ListBox1.ListCount - 1, 1) = _
ActiveSheet.Cells(10, x).Value
ListBox1.List(ListBox1.ListCount - 1, 2) = _
ActiveSheet.Cells(11, x).Value
Next x


End Sub

Once the listbox is populated ..... the user then multi selects the items
they want to copy.
These items are then copied to another worksheet in coulmn B starting with
cell 14 (going down).
To execute the code ... the user clicks a command button and the following
code runs:
Dim i As Integer
Dim j As Integer

With listbox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
Range("description").Offset(j, 0).Value = .List(i)
j = j + 1
End If
Next i
End With


This works...but it only copies and pastes the data in the first cell of
each item listed in the listbox (d9, e,9, f9, and so on) .
I need it to pick up the other cells that make up the item in the list box.

Not sure how to change the code to do that!!

Any help is greatly appreciated.

Thanks in advance..
Kimberly
 
S

Smalltalk_vb

I think the listbox has a list property you can access.

the first argument will be the row, the second is the
column

lstFund.List(1, 3)
 

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