Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Listindex strange problem

Works perfect, thanks Rob.


"Rob Bovey" wrote in message
...
"Amit Shanker" wrote in message
...
Yes, it is indeed a multiselect listbox, with a checkbox shown against
each item. If this is expected behaviour, then perhaps you could suggest
a solution to my following problem :

What I need to do is this : In this multiselect listbox, if no item is
checked, then when I click the OK button on the userform, it should
simply unload the userform and quit. How do I trap the fact that no check
mark is there against any item (so far of course I was trying to use
ListIndex = -1)?


Hi Amit,

In a multi-select listbox you need to loop through each item in the
list and check the Selected property of each to determine if any items are
selected. Here's an example:

Private Sub CommandButton1_Click()
Dim bSelected As Boolean
Dim lIndex As Long
For lIndex = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lIndex) Then bSelected = True
Next lIndex
If Not bSelected Then Unload Me ''' Nothing selected.
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm




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
Userform problem (Listindex) jgmiddel Excel Discussion (Misc queries) 1 April 26th 06 01:34 PM
Strange Problem Perry Excel Discussion (Misc queries) 7 April 12th 06 09:52 PM
Strange Problem... Sujesh Excel Discussion (Misc queries) 6 December 30th 05 02:56 PM
listbox listindex problem jacob Excel Programming 2 August 25th 04 08:46 AM
Strange problem Stuart[_8_] Excel Programming 1 October 3rd 03 12:14 AM


All times are GMT +1. The time now is 02:58 AM.

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"