ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trapping NO selections (https://www.excelbanter.com/excel-programming/322720-trapping-no-selections.html)

Otto Moehrbach

Trapping NO selections
 
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in the
ListBox. I have the following argument that is True if no selections are
made. This code is in the beginning of the macro that is called by the OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then



Rob Bovey

Trapping NO selections
 
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in the
ListBox. I have the following argument that is True if no selections are
made. This code is in the beginning of the macro that is called by the OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then


Hi Otto,

No, that won't work with a multi-select listbox. In this case you have
to loop through each item in the list and check its Selected property. If
all Selected properties return False then nothig is 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 MsgBox "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



Tom Ogilvy

Trapping NO selections
 
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in the
ListBox. I have the following argument that is True if no selections are
made. This code is in the beginning of the macro that is called by the OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then





Otto Moehrbach

Trapping NO selections
 
Tom
Now I'm in a quandary. Bob says No and you say Yes. I tried the
following code and I don't get the "Nothing" MsgBox when no selections are
made. Help!! Otto
If UFMgtFee.lbNMFee.ListIndex = -1 Then
MsgBox = "Nothing"
Unload UFMgtFee
Else
'Do stuff with the selections
End If
"Tom Ogilvy" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in the
ListBox. I have the following argument that is True if no selections are
made. This code is in the beginning of the macro that is called by the
OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then







Tom Ogilvy

Trapping NO selections
 
Sorry - missed the Multi-selection part - see Rob's answer.

for some reason I started reading on this line:
I want to act on the instance wherein the user makes no selections in the
ListBox.


--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in

the
ListBox. I have the following argument that is True if no selections

are
made. This code is in the beginning of the macro that is called by the

OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then







Otto Moehrbach

Trapping NO selections
 
Rob
Thanks for the help. You guys are invaluable. Otto
"Rob Bovey" wrote in message
...
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in the
ListBox. I have the following argument that is True if no selections are
made. This code is in the beginning of the macro that is called by the
OK button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then


Hi Otto,

No, that won't work with a multi-select listbox. In this case you have
to loop through each item in the list and check its Selected property. If
all Selected properties return False then nothig is 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 MsgBox "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





Otto Moehrbach

Trapping NO selections
 
Tom
Thanks for that correction. I take it from what you said that your
original response is correct for a 'MultiSelectSingle' ListBox. Is that
correct? Otto
"Tom Ogilvy" wrote in message
...
Sorry - missed the Multi-selection part - see Rob's answer.

for some reason I started reading on this line:
I want to act on the instance wherein the user makes no selections in
the
ListBox.


--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in

the
ListBox. I have the following argument that is True if no selections

are
made. This code is in the beginning of the macro that is called by the

OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then









Tom Ogilvy

Trapping NO selections
 
Otto,
Sorry for the confusion. Hopefully by now you read my other post that said
I had missed the part about the multi-select setting. Go with Rob's
solution.

I thought it was peculiar that you were asking this question - guess that
should have tipped me off that I was missing something.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Tom
Now I'm in a quandary. Bob says No and you say Yes. I tried the
following code and I don't get the "Nothing" MsgBox when no selections are
made. Help!! Otto
If UFMgtFee.lbNMFee.ListIndex = -1 Then
MsgBox = "Nothing"
Unload UFMgtFee
Else
'Do stuff with the selections
End If
"Tom Ogilvy" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in

the
ListBox. I have the following argument that is True if no selections

are
made. This code is in the beginning of the macro that is called by the
OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then









Tom Ogilvy

Trapping NO selections
 
for the multiselect property set to fmMultiSelectSingle - yes.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Tom
Thanks for that correction. I take it from what you said that your
original response is correct for a 'MultiSelectSingle' ListBox. Is that
correct? Otto
"Tom Ogilvy" wrote in message
...
Sorry - missed the Multi-selection part - see Rob's answer.

for some reason I started reading on this line:
I want to act on the instance wherein the user makes no selections in
the
ListBox.


--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections in

the
ListBox. I have the following argument that is True if no selections

are
made. This code is in the beginning of the macro that is called by

the
OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then











Otto Moehrbach

Trapping NO selections
 
Thanks Tom. Otto
"Tom Ogilvy" wrote in message
...
for the multiselect property set to fmMultiSelectSingle - yes.

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Tom
Thanks for that correction. I take it from what you said that your
original response is correct for a 'MultiSelectSingle' ListBox. Is that
correct? Otto
"Tom Ogilvy" wrote in message
...
Sorry - missed the Multi-selection part - see Rob's answer.

for some reason I started reading on this line:
I want to act on the instance wherein the user makes no selections in
the
ListBox.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Yes.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I have a UF with a multi-selection ListBox, lbNMFee.
I want to act on the instance wherein the user makes no selections
in
the
ListBox. I have the following argument that is True if no
selections
are
made. This code is in the beginning of the macro that is called by

the
OK
button click.
Is this correct? Thanks for your help. Otto

If UFMgtFee.lbNMFee.ListIndex = -1 Then














All times are GMT +1. The time now is 04:52 PM.

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