Multiselect Boxes

J

Jase

Hi All

I have a form setup with a multiselect box in it, and to
determine which bits have been selected I am using
multiselectbox.selected(listnumber) so effectively I loop
through the list and ask eash member if it is selected.

Unfortunately this does not seem to be working??

Is there something obvious that I am missing?

Code fragment :

for x = 0 to listcount
if listbox.selected(x) then
<do stuff>
end if
next x

Thanks heaps
Jase
 
T

Tom Ogilvy

Assume your listbox is named Listbox1 and this code is in the Userform code
module.

Dim sStr as String
Dim x as Long
for x = 0 to Listbox1.listcount - 1
if listbox1.selected(x) then
sStr = sStr & listbox1.list(x) & vbNewline
end if
next x
msgbox sStr

since the list is zero based, you need to loop to 1 less than listcount.
 
V

Vasant Nanavati

Hi Jase:

A few errors in your syntax, corrected below:

Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Debug.Print ListBox1.List(i)
End If
Next i

Regards,

Vasant.
 

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