#1   Report Post  
Posted to microsoft.public.excel.programming
TAM TAM is offline
external usenet poster
 
Posts: 10
Default VBA ListBox

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA ListBox

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


"TAM" wrote in message
t...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA ListBox

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)

"TAM" wrote in message
t...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
TAM TAM is offline
external usenet poster
 
Posts: 10
Default VBA ListBox

Many thanks for your help
"TAM" wrote in message
t...
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default VBA ListBox

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

In article ,
says...
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Listbox B if LIstbox A equals Kim K Excel Discussion (Misc queries) 2 October 31st 06 07:03 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"