Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default identifying multi-select items in a listbox

I have a macro that fills a form with 2 listboxes (single). The user selects
1 items from each listbox to match.....Works great......The listbox is
populated from the data source (hidden sheet) in the workbook.

However, and isn't there always a however, the users have requested that the
matching process allow multiple items to be selected from each listbox.
Sounds easy enough but it is more challenging than I thought.

Once the items are selected, they are moved to a "new" sheet and then
deleted from the data source sheet and the form is re-populated with the
first visible item being the index + 1. I'm having trouble getting the
individual indexes when someone selects more than one. I have tried using
the code below but I'm not able to get the individual indexes.

Any suggestions would be greatly appreciated. Thanks for the
help....FYI....this is one of the first times I have programmed listboxes so
I think that is probably part of the problem....

Sub Find_LB1_Item()
q = 1
For SR1 = 0 To LB1.ListCount - 1
If LB1.Selected(SR1) = True Then
ReDim Preserve SelRef1(1 To q)
ReDim Preserve SelRow1(1 To q)
ReDim Preserve TI1(1 To q)

SelRef1(q) = LB1.List(SR1, 0)

If Len(LB1.List(SR1, 4)) = 0 Then
SelAmt1 = 0
Else
SelAmt1 = SelAmt1 + LB1.List(SR1, 4)
End If

FoundLB1 = True
SelRow1(q) = LB1.List(SR1, 5)
TI1(q) = LB1.ListIndex ' this line
q = q + 1

End If

Next SR1

End Sub
--
JT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default identifying multi-select items in a listbox

I think you want to use the Selected property of the ListBox. For example,

Dim N As Long
With Me.ListBox1
For N = 0 To .ListCount - 1
If .Selected(N) = True Then
Debug.Print "Item " & CStr(N) & " was selected."
Else
Debug.Print "Item " & CStr(N) & " was not selected."
End If
Next N
End With

This assumes, of course, that you have set the MultiSelect property
appropriately.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"JT" wrote in message
...
I have a macro that fills a form with 2 listboxes (single). The user
selects
1 items from each listbox to match.....Works great......The listbox is
populated from the data source (hidden sheet) in the workbook.

However, and isn't there always a however, the users have requested that
the
matching process allow multiple items to be selected from each listbox.
Sounds easy enough but it is more challenging than I thought.

Once the items are selected, they are moved to a "new" sheet and then
deleted from the data source sheet and the form is re-populated with the
first visible item being the index + 1. I'm having trouble getting the
individual indexes when someone selects more than one. I have tried using
the code below but I'm not able to get the individual indexes.

Any suggestions would be greatly appreciated. Thanks for the
help....FYI....this is one of the first times I have programmed listboxes
so
I think that is probably part of the problem....

Sub Find_LB1_Item()
q = 1
For SR1 = 0 To LB1.ListCount - 1
If LB1.Selected(SR1) = True Then
ReDim Preserve SelRef1(1 To q)
ReDim Preserve SelRow1(1 To q)
ReDim Preserve TI1(1 To q)

SelRef1(q) = LB1.List(SR1, 0)

If Len(LB1.List(SR1, 4)) = 0 Then
SelAmt1 = 0
Else
SelAmt1 = SelAmt1 + LB1.List(SR1, 4)
End If

FoundLB1 = True
SelRow1(q) = LB1.List(SR1, 5)
TI1(q) = LB1.ListIndex ' this line
q = q + 1

End If

Next SR1

End Sub
--
JT


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
Hi-lighting items in a multi-select List box Dan Excel Programming 6 June 4th 07 10:44 PM
Listbox Multi Select MikeT Excel Programming 2 July 27th 06 08:25 PM
using a multi-select listbox to pull data dreamz[_6_] Excel Programming 2 October 17th 05 10:56 PM
Multi-select listbox help! John[_60_] Excel Programming 3 October 9th 04 01:57 AM
multi select listbox Paul Mueller Excel Programming 2 June 10th 04 09:08 PM


All times are GMT +1. The time now is 06:12 PM.

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

About Us

"It's about Microsoft Excel"