Multiselect Boxes

  • Thread starter Thread starter Jase
  • Start date Start date
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
 
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.
 
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.
 
Back
Top