VBA ListBox

T

TAM

Can anyone please tell me how to check that the user has made a selection in
a VBA ListBox - I need to warn them if no selection has been made

Thanks

TAM
 
C

Chip Pearson

If no item has been selected in the listbox, the ListIndex
property will be -1. E.g.,

If Me.ListBox1.ListIndex = -1 Then
MsgBox "You must select an item"
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
B

Bob Phillips

Here is some code for a userform listbox

Dim i As Long
Dim fSelected As Boolean
fSelected = False
With Me.ListBox1
For i = 1 To .ListCount
If .Selected(i) Then
fSelected = True
Exit For
End If
Next i
End With

If Not fSelected Then
MsgBox "Nothing selected"
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
T

Tushar Mehta

Check the ListIndex property. It will be -1 if no selection has been
made. For more, check the VBA help.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
Top