View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_2_] Dick Kusleika[_2_] is offline
external usenet poster
 
Posts: 66
Default listboxs and combo boxes

That's a good point, Tom. If, for some reason, you couldn't sort the data
on the worksheet, it would probably still be easier to create a new
worksheet, copy the data, sort it, populate the listbox (with AddItem) and
delete the sheet.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com


Tom Ogilvy wrote:
Dick's links would take a lot of time to adapt to sort an array of more
than two columns. If you are up to the task, drive on, but it would be
easier to sort on the sheet using the built in sort, then grab the whole
range and put it in the list in one step.


"Dick Kusleika" wrote in message
...
Rich

Here are two options for you to consider. First, put all the information
from the range in the listbox (you can hide columns you don't want the
user to see by making it's width 0) and populate the textboxes using the
Column property of the listbox.

Another option is not to use the index to find the other data. You could
use the Find method, for instance, to find the row that matches the
listbox and populate the textboxes based on that.

Either way, you need to put your data (either 1 column or all columns)
into an array and sort the array before you populate the listbox.

The bonus third option is to sort the range that contains the data before
you populate the listbox. I don't know if you can do that, however.

To sort a listbox, see here
http://www.dicks-blog.com/excel/2004...g_listbox.html

To sort a multicolumn listbox, see here
http://www.dicks-blog.com/excel/2004...g_a_multi.html

A Find Method example can be seen here
http://www.dicks-blog.com/excel/2004...nd_method.html

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Rich Cooper" wrote in message
...
It is a single column list book. The data is on another worksheet. I
have the list box using a range of nmaes and using the index i am able
to get the other info about the person and display it in a txtbox. I
just want to know if i can sort the data the same way. Or do i have to
make it an array. If i make it an array how do i go about doing that.
"Tom Ogilvy" wrote in message
...
You say the listbox has a bunch of names - then you talk about things
like zipcode, state, as so forth. Is this a multicolumn listbox with
all that information for each name?

There is no built in method to sort a listbox's list.

Other than that, you would have to grab the list as an array, sort it
according to your selection in the combobox, then put it back in the
listbox.

What kind of help are you looking for?

--
Regards,
Tom Ogilvy



"Rich Cooper" wrote in message
...
I am working with both a combo box and a list box. The list box has
a bunch of names. The combo box has some options and i want those
options to sort and filter the listbox. How do i do that? Some of
the options are by state, zipcode, city, last nmae, firstname? Any
help wouldbe greatly appreciated.