Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Having a hard time with listbox
Thanks. That was better than what I was about to do...
Thurman |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Listbox 2 takes the value of Listbox 1 | Excel Discussion (Misc queries) | |||
listbox B conditional of input in Listbox A | Excel Discussion (Misc queries) | |||
Listbox B if LIstbox A equals | Excel Discussion (Misc queries) | |||
Can I save to hard drive AND my flash drive at the same time? | Excel Discussion (Misc queries) | |||
Sorting ListBox results or transposing ListBox values to other cells for sorting | Excel Programming |