![]() |
ListBox Value
Does anybody know of a way to capture a user highlighted item out of a list
box? Is there another tool that would be more appropriate? I would like to then take that value and do more but I am stuck on this. I can't seem to find anything to guide me in help or the books that I have. Thanks Carrie -- Message posted via http://www.officekb.com |
ListBox Value
On 16 Feb, 15:02, "Carrie_Loos via OfficeKB.com" <u34134@uwe wrote:
Does anybody know of a way to capture a user highlighted item out of a list box? Is there another tool that would be more appropriate? I would like to then take that value and do more but I am stuck on this. I can't seem to find anything to guide me in help or the books that I have. Thanks Carrie -- Message posted viahttp://www.officekb.com Could you please copy your code into the thread. If I have a listbox from the toolbox then the name of the listbox will return the value. If a sheet has a listbox (named lstbox) and a button (named cmdButton) on it then the following should give the value of the listbox in a message when the button is pressed: '============================ Private Sub cmdButton_Click() On Error Resume Next MsgBox LstBox.value End Sub '============================ this will do the same, as the property value can be omitted (it being the default property of this object): '============================ Private Sub cmdButton_Click() On Error Resume Next MsgBox LstBox End Sub '============================ hope this helps jason |
ListBox Value
For a single select listbox you can use the ListBox1.Value or the
ListBox1.Selected(index) syntax, (assuming ListBox1). Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount + 1 Range("A2") = ListBox1.Selected(i) Next "Carrie_Loos via OfficeKB.com" wrote: Does anybody know of a way to capture a user highlighted item out of a list box? Is there another tool that would be more appropriate? I would like to then take that value and do more but I am stuck on this. I can't seem to find anything to guide me in help or the books that I have. Thanks Carrie -- Message posted via http://www.officekb.com |
ListBox Value
hi
what the user select is the value. dim s as long 'or string s = listbox1.value range("A1")= s this does not apply to multiselect list boxes. Regards FSt1 "Carrie_Loos via OfficeKB.com" wrote: Does anybody know of a way to capture a user highlighted item out of a list box? Is there another tool that would be more appropriate? I would like to then take that value and do more but I am stuck on this. I can't seem to find anything to guide me in help or the books that I have. Thanks Carrie -- Message posted via http://www.officekb.com |
ListBox Value
This works great! I have been stuck for days! Thanks!
JLGWhiz wrote: For a single select listbox you can use the ListBox1.Value or the ListBox1.Selected(index) syntax, (assuming ListBox1). Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount + 1 Range("A2") = ListBox1.Selected(i) Next Does anybody know of a way to capture a user highlighted item out of a list box? Is there another tool that would be more appropriate? I would like to [quoted text clipped - 3 lines] Thanks Carrie -- Message posted via http://www.officekb.com |
ListBox Value
This: For i = 1 To ListBox1.ListCount + 1
Should have been: For i = 1 To ListBox1.ListCount - 1 "Carrie_Loos via OfficeKB.com" wrote: This works great! I have been stuck for days! Thanks! JLGWhiz wrote: For a single select listbox you can use the ListBox1.Value or the ListBox1.Selected(index) syntax, (assuming ListBox1). Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount + 1 Range("A2") = ListBox1.Selected(i) Next Does anybody know of a way to capture a user highlighted item out of a list box? Is there another tool that would be more appropriate? I would like to [quoted text clipped - 3 lines] Thanks Carrie -- Message posted via http://www.officekb.com |
ListBox Value
For a single select listbox you can use the ListBox1.Value or the
ListBox1.Selected(index) syntax, (assuming ListBox1). Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount + 1 Range("A2") = ListBox1.Selected(i) Next I think for your loop to do what you intended, it would need to look like this... For i = 1 To ListBox1.ListCount + 1 If ListBox1.Selected(i) Then Range("A2") = ListBox1.Selected(i) Exit For End If Next otherwise, it will report the selected status of the last item in the list. However, you don't need to use a loop to find the item.... you can use the ListIndex property to get the selected item's index... Range("A2") = ListBox1.Selected(ListBox1.ListIndex) Rick |
ListBox Value
Yeah, I just wanted to illustrate the use of the index number. Guess I
should be more careful about syntax and structure. "Rick Rothstein (MVP - VB)" wrote: For a single select listbox you can use the ListBox1.Value or the ListBox1.Selected(index) syntax, (assuming ListBox1). Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount + 1 Range("A2") = ListBox1.Selected(i) Next I think for your loop to do what you intended, it would need to look like this... For i = 1 To ListBox1.ListCount + 1 If ListBox1.Selected(i) Then Range("A2") = ListBox1.Selected(i) Exit For End If Next otherwise, it will report the selected status of the last item in the list. However, you don't need to use a loop to find the item.... you can use the ListIndex property to get the selected item's index... Range("A2") = ListBox1.Selected(ListBox1.ListIndex) Rick |
ListBox Value
For a multi-select ListBox, you should be able to get the item currently
being **pointed** to (whether selected or not) using this... ItemPointedAt = ListBox1.List(ListBox1.ListIndex) Rick "FSt1" wrote in message ... hi what the user select is the value. dim s as long 'or string s = listbox1.value range("A1")= s this does not apply to multiselect list boxes. Regards FSt1 "Carrie_Loos via OfficeKB.com" wrote: Does anybody know of a way to capture a user highlighted item out of a list box? Is there another tool that would be more appropriate? I would like to then take that value and do more but I am stuck on this. I can't seem to find anything to guide me in help or the books that I have. Thanks Carrie -- Message posted via http://www.officekb.com |
ListBox Value
Thanks for all the info. Since I am realitively new to VBA without any formal
training some simple things can be lost so I apologize if I am asking a silly question. The only code I could get to work was the suggestion you had earlier. This is for a MultiList Box. I have somehow botched this up. I could not get the option button to "unload" someone gave me this clear the option button code which causes me a couple of problems 1) The option button never shows "clicked" and 2) I have to re-click the option button after a list box selection to get the code to run and show the selection in cell A1. I just can't seem to get past this portion. Any suggestions? Private Sub OptionButton41_Click() ListBox1.RowSource = "Classes!Customer" Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount - 1 Range("A2") = ListBox1.Selected(i) Next Dim ctrl As Control For Each ctrl In UserForm1.Controls If TypeOf ctrl Is MSForms.TextBox Then ctrl.Value = "" ElseIf TypeOf ctrl Is MSForms.OptionButton Then ctrl.Value = False End If Next ctrl End Sub JLGWhiz wrote: Yeah, I just wanted to illustrate the use of the index number. Guess I should be more careful about syntax and structure. For a single select listbox you can use the ListBox1.Value or the ListBox1.Selected(index) syntax, (assuming ListBox1). [quoted text clipped - 21 lines] Rick -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200802/1 |
ListBox Value
Carrie, The code I gave you was only to illustrate the syntax for the value
of a single select list box. They were the Value and the Index properties of the list box. To fully understand what I gave you, you should use the VBA help file by opening the VB editor and searching for ListBox, ListIndex, Selected(forms) and ListCount. There is a lot of information there that will explain when you can and cannot use certain properties of the ListBox. I would suggest that you practice using the different methods of applying the properties on a data base that is not for official use. The more you experiment on mock up models, the more you will come to understand how the code works. "Carrie_Loos via OfficeKB.com" wrote: Thanks for all the info. Since I am realitively new to VBA without any formal training some simple things can be lost so I apologize if I am asking a silly question. The only code I could get to work was the suggestion you had earlier. This is for a MultiList Box. I have somehow botched this up. I could not get the option button to "unload" someone gave me this clear the option button code which causes me a couple of problems 1) The option button never shows "clicked" and 2) I have to re-click the option button after a list box selection to get the code to run and show the selection in cell A1. I just can't seem to get past this portion. Any suggestions? Private Sub OptionButton41_Click() ListBox1.RowSource = "Classes!Customer" Range("A1") = ListBox1.Value For i = 1 To ListBox1.ListCount - 1 Range("A2") = ListBox1.Selected(i) Next Dim ctrl As Control For Each ctrl In UserForm1.Controls If TypeOf ctrl Is MSForms.TextBox Then ctrl.Value = "" ElseIf TypeOf ctrl Is MSForms.OptionButton Then ctrl.Value = False End If Next ctrl End Sub JLGWhiz wrote: Yeah, I just wanted to illustrate the use of the index number. Guess I should be more careful about syntax and structure. For a single select listbox you can use the ListBox1.Value or the ListBox1.Selected(index) syntax, (assuming ListBox1). [quoted text clipped - 21 lines] Rick -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200802/1 |
ListBox Value
Thanks - Actually I did understand the Value and Index properties in which I
will be changing to suit what my needs are....What was going on that I did not understand and I have since figured out was the simple context of the the Multi-List construction. When I created the multi-list on the userform I had several option buttons that were created and I was trying to run the code through those. Whereas, I should have been running the code through the ListBox option and I was not aware and/or thinking about that it was created. It all makes sense now. I really was confused about the placement. Again, thanks for all your help. Each one of these exercises may be painful but bountiful for me in so many ways. Just wanted to say how much I appreciate everyones input. JLGWhiz wrote: Carrie, The code I gave you was only to illustrate the syntax for the value of a single select list box. They were the Value and the Index properties of the list box. To fully understand what I gave you, you should use the VBA help file by opening the VB editor and searching for ListBox, ListIndex, Selected(forms) and ListCount. There is a lot of information there that will explain when you can and cannot use certain properties of the ListBox. I would suggest that you practice using the different methods of applying the properties on a data base that is not for official use. The more you experiment on mock up models, the more you will come to understand how the code works. Thanks for all the info. Since I am realitively new to VBA without any formal training some simple things can be lost so I apologize if I am asking a silly [quoted text clipped - 35 lines] Rick -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200802/1 |
All times are GMT +1. The time now is 04:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com