How to determine if any row is selected in a listbox How to determine if any row is selected in a listbox vba vba

How to determine if any row is selected in a listbox


A list box has the ItemsSelected property which returns a read-only reference to the hidden ItemsSelected collection. And you can ask for the Count property of that collection ...

MsgBox Me.YourListBoxName.ItemsSelected.Count & " items selected"


The code

If ListBox.ListIndex = -1 then  MsgBox "Nothing selected"end if

should help...


this worked for me...a mix of both comments before, thank you both

If List4.ItemsSelected.Count = 0 Then  MsgBox "Nothing selected"

So if nothing is selected I get the message