ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiselect Listbox - identify if item picked (https://www.excelbanter.com/excel-programming/368215-multiselect-listbox-identify-if-item-picked.html)

apndas[_12_]

Multiselect Listbox - identify if item picked
 

Hello

the next conundrum i have in relation to my ongoing userform
development. basically i want to confirm that at least one item has
been selected from my listbox before allowing my commandbutton to
proceed. help!!

(this part i can do) in the event that nothing has been selected i want
to exit sub and prompt user to pick a item from the listbox - so it's
just the first bit that has me stumped. i can't use listindex because
of the multiselect function.

regards
darren


--
apndas
------------------------------------------------------------------------
apndas's Profile: http://www.excelforum.com/member.php...o&userid=36137
View this thread: http://www.excelforum.com/showthread...hreadid=564556


NickHK

Multiselect Listbox - identify if item picked
 
Seems like you have to use the _Change event instead of the _Click events to
detect a click, in Excel2K; seems bizarre as you are clicking without
changing anything.. but anyway.
Private Sub ListBox1_Change()
Dim i As Long
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
CommandButton1.Enabled = True
Exit Sub
End If
Next
End With
CommandButton1.Enabled = False
End Sub

NickHK

"apndas" wrote in
message ...

Hello

the next conundrum i have in relation to my ongoing userform
development. basically i want to confirm that at least one item has
been selected from my listbox before allowing my commandbutton to
proceed. help!!

(this part i can do) in the event that nothing has been selected i want
to exit sub and prompt user to pick a item from the listbox - so it's
just the first bit that has me stumped. i can't use listindex because
of the multiselect function.

regards
darren


--
apndas
------------------------------------------------------------------------
apndas's Profile:

http://www.excelforum.com/member.php...o&userid=36137
View this thread: http://www.excelforum.com/showthread...hreadid=564556




apndas[_13_]

Multiselect Listbox - identify if item picked
 

Thanks for your reply Nick - that sub works however in disabling the
command button it does not allow me to then select a manifest # and
continue processing my invoice, I just want it to alert me that nothing
has been selected and setfocus on the manifest list and be then able to
select something - that sounds a bit circular - I hope I'm making some
sense.

regards
Darren


--
apndas
------------------------------------------------------------------------
apndas's Profile: http://www.excelforum.com/member.php...o&userid=36137
View this thread: http://www.excelforum.com/showthread...hreadid=564556


NickHK[_3_]

Multiselect Listbox - identify if item picked
 
You mean something like this ?

Private Sub ListBox1_Change()
Dim i As Long
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
'Do nothing
Exit Sub
End If
Next
End With
MsgBox "Missing some selection"
ListManifest.SetFocus

End Sub

NickHK


"apndas" ¼¶¼g©ó¶l¥ó·s»D:apndas.2bk3jg_1153923607.6654@excel forum-nospam.com...

Thanks for your reply Nick - that sub works however in disabling the
command button it does not allow me to then select a manifest # and
continue processing my invoice, I just want it to alert me that nothing
has been selected and setfocus on the manifest list and be then able to
select something - that sounds a bit circular - I hope I'm making some
sense.

regards
Darren


--
apndas
------------------------------------------------------------------------
apndas's Profile:
http://www.excelforum.com/member.php...o&userid=36137
View this thread: http://www.excelforum.com/showthread...hreadid=564556




apndas[_14_]

Multiselect Listbox - identify if item picked
 

Hi Nick

Unfortunately that does not work, if I don't select anything in the
listbox (1 or more items) it still processes the invoice when i click
the commandbutton, i think the test needs to be in the
commandbutton_click code, which i also tried but could still not get it
to work???? aagghh!!!


--
apndas
------------------------------------------------------------------------
apndas's Profile: http://www.excelforum.com/member.php...o&userid=36137
View this thread: http://www.excelforum.com/showthread...hreadid=564556


NickHK

Multiselect Listbox - identify if item picked
 
You have the code to test if you have any selection or not, so it's up to
you decide when it is called.

NickHK

"apndas" wrote in
message ...

Hi Nick

Unfortunately that does not work, if I don't select anything in the
listbox (1 or more items) it still processes the invoice when i click
the commandbutton, i think the test needs to be in the
commandbutton_click code, which i also tried but could still not get it
to work???? aagghh!!!


--
apndas
------------------------------------------------------------------------
apndas's Profile:

http://www.excelforum.com/member.php...o&userid=36137
View this thread: http://www.excelforum.com/showthread...hreadid=564556





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

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