Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default 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



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default 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

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 listbox cannot get listbox.value to transfer back to main sub [email protected] Excel Programming 1 May 17th 06 09:44 PM
avoiding duplicates in listbox (added from another listbox) KR Excel Programming 4 March 14th 06 08:17 PM
VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox) modjoe23 Excel Programming 3 August 18th 05 02:35 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM


All times are GMT +1. The time now is 06:56 PM.

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"