Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Transferring from both columns of a listbox to another

I have two two-column listboxes in a userform. I want to pass selected
elements of the first listbox to the other, but I can't seem to figure
out how to get both columns to pass.

The first column is a CAS registry number and the second column is the
Chemical Name. I want to be able to (multi)select these from the first
listbox (populated by a worksheet range referenced by the RowSource
property), run my code, and have these selected elements show up in
the second listbox exactly as in the first. Instead, I only get the
first column (the CAS registry number).

Here's my code:

================

Private Sub CmdAddCAS_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer

'Make sure something is selected
If LBoxCAS.ListIndex = -1 Then Exit Sub

'Make sure no duplicates
For j = 0 To LBoxCASSelected.ListCount - 1
For i = 0 To LBoxCAS.ListCount - 1
If LBoxCAS.Selected(i) Then
If LBoxCAS.List(i) = LBoxCASSelected.List(j) Then
Beep
Exit Sub
End If
End If
Next i
Next j

'Make transfer
For k = 0 To LBoxCAS.ListCount - 1
If LBoxCAS.Selected(k) Then
LBoxCASSelected.AddItem LBoxCAS.List(k)
End If
Next k
End Sub

=================

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default Transferring from both columns of a listbox to another


You have to specify the column. First column is 0, second column is 1...
Dim k As Long
For k = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(k) Then
ListBox2.AddItem ListBox1.List(k, 0)
ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(k, 1)
End If
Next k
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Edward"
wrote in message
I have two two-column listboxes in a userform. I want to pass selected
elements of the first listbox to the other, but I can't seem to figure
out how to get both columns to pass.

The first column is a CAS registry number and the second column is the
Chemical Name. I want to be able to (multi)select these from the first
listbox (populated by a worksheet range referenced by the RowSource
property), run my code, and have these selected elements show up in
the second listbox exactly as in the first. Instead, I only get the
first column (the CAS registry number).

Here's my code:

================

Private Sub CmdAddCAS_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer

'Make sure something is selected
If LBoxCAS.ListIndex = -1 Then Exit Sub

'Make sure no duplicates
For j = 0 To LBoxCASSelected.ListCount - 1
For i = 0 To LBoxCAS.ListCount - 1
If LBoxCAS.Selected(i) Then
If LBoxCAS.List(i) = LBoxCASSelected.List(j) Then
Beep
Exit Sub
End If
End If
Next i
Next j

'Make transfer
For k = 0 To LBoxCAS.ListCount - 1
If LBoxCAS.Selected(k) Then
LBoxCASSelected.AddItem LBoxCAS.List(k)
End If
Next k
End Sub

=================

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 09:27 PM
Listbox B if LIstbox A equals Kim K Excel Discussion (Misc queries) 2 October 31st 06 08:03 PM
transferring formats jonas.ornborg Excel Worksheet Functions 7 May 23rd 06 02:35 PM
transferring files DAZED AND CONFUSED Excel Worksheet Functions 2 September 24th 05 05:33 PM
multiple columns / rows to be referenced through a listbox Hru48 Excel Discussion (Misc queries) 0 July 4th 05 05:12 PM


All times are GMT +1. The time now is 07:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"