ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Transferring items between multicolumn listboxes (https://www.excelbanter.com/excel-discussion-misc-queries/160055-transferring-items-between-multicolumn-listboxes.html)

[email protected]

Transferring items between multicolumn listboxes
 
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"


joel

Transferring items between multicolumn listboxes
 
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

" wrote:

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"



[email protected]

Transferring items between multicolumn listboxes
 
On Sep 28, 9:23 am, Joel wrote:
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.



All times are GMT +1. The time now is 06:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com