View Full Version : Check no selection in a listbox..

04-03-2008, 02:08 AM

I know that this is a simple one but i'm simple, so help me, lol..

I want to trap error for if nothing has been selected in a listbox (its set to multiselect btw, just in case that matters)..

I tried this:

If LayoutLIST.ListIndex = -1 Then
MsgBox "No, its not selected"
Exit Sub
End If

...as a test but it didn't seem to work (saw that code somewhere online - not the msgbox bit)..

I know that the listbox in VBA is an MSForms listbox not a native VB one, so has different properties and all the info i've found online on how to do this doesn't work, so was wondering if someone on here knew what to do..

04-03-2008, 02:40 AM
G'day Paul, Welcome to the forum. One of the whizz kids will be along shortly to assist you with your request. :hi:

04-03-2008, 03:00 AM
Thanks Aussiebear, glad to be here

04-03-2008, 03:17 AM
http://www.vbaexpress.com/kb/getarticle.php?kb_id=369 has the necessary info that you want.