Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Capturing Listbox Selections

Hi,
I've got two multi-select listboxes on a userform. The idea is that
listbox A contains all possible items and listbox B is a subset of A
defined by the user. I'm struggling with capturing the selected
values in A so that they can be copied to B. Here is my code:

With frmManageGroups.lbxA
For x = 0 To .ListCount - 1
If .Selected(x) = True Then
frmManageGroups.lbxB.AddItem .List(.ListIndex)
.Selected(x) = False
End If
Next
End With

The way that this is written, it only copies the last item selected in
listbox A. For example, if the listbox A contains the letters A,B,
and C as its items and the user selects A and C, my code copies the
letter C twice to listbox B instead of the letters A and C.

Can anybody help?
Thanks,
Randy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Capturing Listbox Selections

Not usre what you were really tryiing to do. this is how I prevent
duplicates from getting into a Listbox. I checd the with statement from A to
b. I'm checking to see if the item is already in the list box B

With frmManageGroups.lbxB
For x = 0 To .ListCount - 1
Found = False
If frmManageGroups.lbxB = .List(x) Then

Found = True
exit for
End If
Next
if found = False then
frmManageGroups.lbxB.AddItem
end if
End With


"Randy" wrote:

Hi,
I've got two multi-select listboxes on a userform. The idea is that
listbox A contains all possible items and listbox B is a subset of A
defined by the user. I'm struggling with capturing the selected
values in A so that they can be copied to B. Here is my code:

With frmManageGroups.lbxA
For x = 0 To .ListCount - 1
If .Selected(x) = True Then
frmManageGroups.lbxB.AddItem .List(.ListIndex)
.Selected(x) = False
End If
Next
End With

The way that this is written, it only copies the last item selected in
listbox A. For example, if the listbox A contains the letters A,B,
and C as its items and the user selects A and C, my code copies the
letter C twice to listbox B instead of the letters A and C.

Can anybody help?
Thanks,
Randy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Capturing Listbox Selections

frmManageGroups.lbxB.AddItem .List(.ListIndex)

You don't want to use ListIndex there. In a multi-select list box,
ListIndex is the item that has the *focus* in the UI, so if 2 items have
been selected, but C has the focus (whether selected or not!), you'll end up
with 2 C's.

frmManageGroups.lbxB.AddItem .List(x)


HTH,


"Randy" wrote in message
ups.com...
Hi,
I've got two multi-select listboxes on a userform. The idea is that
listbox A contains all possible items and listbox B is a subset of A
defined by the user. I'm struggling with capturing the selected
values in A so that they can be copied to B. Here is my code:

With frmManageGroups.lbxA
For x = 0 To .ListCount - 1
If .Selected(x) = True Then
frmManageGroups.lbxB.AddItem .List(.ListIndex)
.Selected(x) = False
End If
Next
End With

The way that this is written, it only copies the last item selected in
listbox A. For example, if the listbox A contains the letters A,B,
and C as its items and the user selects A and C, my code copies the
letter C twice to listbox B instead of the letters A and C.

Can anybody help?
Thanks,
Randy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Capturing Listbox Selections

You're right, George. I just needed (x) and not (.ListIndex).

Thanks to both of you for your advice.

Randy

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
Creating Chart from Userform ListBox selections Corey Charts and Charting in Excel 2 September 8th 08 05:53 AM
Duplicate prevention from Listbox selections to worksheet Casey[_103_] Excel Programming 2 June 12th 06 06:59 PM
How do I retrieve multiple selections from a forms listbox? Wheeler Excel Programming 2 April 21st 05 12:31 AM
Display selections from a listbox in a message box Excel-erate2004[_35_] Excel Programming 2 September 6th 04 12:48 PM
Jumping to chart based on listbox selections ChrisMD Excel Programming 0 July 7th 04 04:42 PM


All times are GMT +1. The time now is 02:41 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"