PDA

View Full Version : Solved: Looping through a shapes listbox



rich_exe
08-01-2008, 04:28 AM
Hi all,

I seem to have got myself a little confused....easily done!

I was previously using a controls listbox, where I could loop through the control to find out which of the items were selected:

For i = 0 To Sheet1.OLEObjects("FirstListBox").Object.ListCount - 1
If Sheet1.OLEObjects("FirstListBox").Object.Selected(i) Then
'my code
End If
Next


Having had a few issues with them, I thought I'd give it a go with a forms listbox (multi-select). I can get the items in the list, but how do I find out if they are selected or not?



For i = 0 To Sheet1.Shapes("FirstListBox").ControlFormat.ListCount - 1
......
Next


Also, if anyone could tell me what the differences are between the two types of listbox I'd be very grateful!

Bob Phillips
08-01-2008, 04:55 AM
With Sheet1.ListBoxes("FirstListBox")

For i = 1 To .ListCount

If .Selected(i) Then

MsgBox .List(i)
End If
Next
End With

rich_exe
08-01-2008, 06:15 AM
Brilliant! Thanks so much!