Transferring items between multicolumn listboxes

N

neversneverland

Hi-
I've been trying to figure out how to move items between multicolumn
listboxes. I have it all expect for one piece. If I select more than
one item from the source listbox, I don't get all of the selected
items, I only get the first item in the selection repeated a number of
times (that number equalling the number of items I originally
selected).

My code is pasted below. Can anyone steer me in a direction?

Thanks

' Variable declarations
Dim iIndex
Dim iInd2
Dim iSel As Long
Dim i As Long
Dim x As Long

' Checks to see if there is anything selected
' in the listbox to add
If ListBox1.ListIndex = -1 Then GoTo SelectError

' Populates listbox2
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
iIndex = .ListIndex
iInd2 = ListBox2.ListCount
ListBox2.AddItem .List(iIndex, 0)
ListBox2.List(iInd2, 1) = .List(iIndex, 1)
ListBox2.List(iInd2, 2) = .List(iIndex, 2)
End If
Next i
End With

Exit Sub

SelectError:
MsgBox "Please make a selection.", vbExclamation + vbOKOnly,
"ERROR"
 
G

Guest

You are not using i in yhour code

from:
For i = 0 To .ListCount - 1
If .Selected(i) Then
iIndex = .ListIndex
to:
For i = 0 To .ListCount - 1
If .Selected(i) Then
iIndex = i
 
N

neversneverland

You are not using i in yhour code

from:
For i = 0 To .ListCount - 1
If .Selected(i) Then
iIndex = .ListIndex
to:
For i = 0 To .ListCount - 1
If .Selected(i) Then
iIndex = i
Dude, that's perfect!

I knew it had to be something small. I think I was just looking at the
code too long... :)

Thanks for your help.
 

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