Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
userform listbox cannot get listbox.value to transfer back to main sub | Excel Programming | |||
avoiding duplicates in listbox (added from another listbox) | Excel Programming | |||
VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox) | Excel Programming | |||
listbox.value not equal to listbox.list(listbox.listindex,0) | Excel Programming | |||
Is refreshing listbox rowsource in listbox click event possible? | Excel Programming |