ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Listbox no selection (https://www.excelbanter.com/excel-programming/423583-re-listbox-no-selection.html)

OssieMac

Listbox no selection
 
Hi John,

If multiselect property set to single then following will tell you if a
selection is made.

Dim LstSelect As Variant

LstSelect = ListBox1.ListIndex

If LstSelect = -1 Then
MsgBox "No selection"
Else
MsgBox ListBox1.Value

End If

However, if multiselect property set to multi then

Dim x As Long
Dim numbSelected

For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
numbSelected = numbSelected + 1
MsgBox ListBox1.List(x)
End If
Next x

If numbSelected = 0 Then
MsgBox "No Selections"

End If


--
Regards,

OssieMac




All times are GMT +1. The time now is 12:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com