Thread: listbox
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default listbox

I assume you mean a ListBox. The following is for an ActiveX ListBox.
However, your code does not make a lot of sense. You can simply use the
following line to obtain the selected value:-

MsgBox Sheets("Sheet1").ListBox1.Value

Following is your code edited:-

For x = 0 To Sheets("Sheet1").ListBox1.ListCount - 1

' If the item is selected...
If Sheets("Sheet1").ListBox1.Selected(x) = True Then

'...display the Selected item.
MsgBox Sheets("Sheet1").ListBox1.List(x)

End If

Next x

Regards,

OssieMac


"geebee" wrote:

hi,

I hae the following in an excel spreadsheet rathr than a userform:

For x = 0 to testbox.ListCount - 1

' If the item is selected...
If testbox.Selected(x) = True Then

'...display the Selected item.
MsgBox testbox.List(x)

End If

Next x

but every time i run the code, i get an "object required" error message.

why would this be happening?

thanks in advance,
geebee