Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Having a hard time with listbox

Sometimes you just get lost in the code. I have a worksheet, now rounding
about 900k in size (sad thing is it only contains 3 pages of visual
reference material and no graphics). In it I have several list boxes that
manipulate the data that I have stored in them using the additem method. I
can easily get the data of a selected item, but now I find myself needing to
know if an item is in the list box from within the VBA code.

Should I ...
A.) Create an array and search the array for the item.
B.) Use a function from within the VBA designed for this perpose and I
am not aware of
C.) Go to the local pub and think about getting a brain transplant

Thanks for any input that is positive...

Thurman


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Having a hard time with listbox

Thurman,

Time for the pub I think <vbg!

Seriously, perhaps you should look at it differently. Where is the data for
the listboxes coming from? Assuming that you have that data somewhere, all
you need to do is search there for an item. I tend to put any data that I
will add to a listbox on a hidden worksheet, and point the boxes at there.
Checking if it's there is then simple.

Other than that you could simply loop through the values and check,
something like

Dim i As Long
For i = 0 To ListBox1.ListCount
If ListBox1.List(i) = "Hannah" Then
MsgBox "Found in item " & i
Exit For
End If
Next


--

HTH

Bob Phillips

"Thurman" wrote in message
...
Sometimes you just get lost in the code. I have a worksheet, now rounding
about 900k in size (sad thing is it only contains 3 pages of visual
reference material and no graphics). In it I have several list boxes that
manipulate the data that I have stored in them using the additem method. I
can easily get the data of a selected item, but now I find myself needing

to
know if an item is in the list box from within the VBA code.

Should I ...
A.) Create an array and search the array for the item.
B.) Use a function from within the VBA designed for this perpose and I
am not aware of
C.) Go to the local pub and think about getting a brain transplant

Thanks for any input that is positive...

Thurman




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Having a hard time with listbox

Since Bob didn't mention it, another possibility is
Listbox1.listindex
gives the location in a list where the selected item is (if you haven't set
the listbox to multiselect - Bob's is the approach for multiselect as well).
Zero is the first location.

Listbox1.Listcount
gives the number of items, so Listbox1.listcount -1 is the last item.

Beyond that, it is unclear what you mean by is in the listbox. I am not
sure how a listbox (as opposed to a combobox) could have a value that is not
in the list?

--
Regards,
Tom Ogilvy


Thurman wrote in message
...
Sometimes you just get lost in the code. I have a worksheet, now rounding
about 900k in size (sad thing is it only contains 3 pages of visual
reference material and no graphics). In it I have several list boxes that
manipulate the data that I have stored in them using the additem method. I
can easily get the data of a selected item, but now I find myself needing

to
know if an item is in the list box from within the VBA code.

Should I ...
A.) Create an array and search the array for the item.
B.) Use a function from within the VBA designed for this perpose and I
am not aware of
C.) Go to the local pub and think about getting a brain transplant

Thanks for any input that is positive...

Thurman




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Having a hard time with listbox

Thanks. That was better than what I was about to do...

Thurman


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
Listbox 2 takes the value of Listbox 1 Illya Teideman Excel Discussion (Misc queries) 3 April 10th 07 03:20 PM
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Listbox B if LIstbox A equals Kim K Excel Discussion (Misc queries) 2 October 31st 06 07:03 PM
Can I save to hard drive AND my flash drive at the same time? Gizelle Excel Discussion (Misc queries) 3 July 24th 06 08:27 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 11:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"