Populating a listbox with values from a sheet.

S

shenlingstyle

Hi everyone, hope you can help me with this one. I'm not very familia
with how listboxes work and how to write code for them. My situation i
as below:

I have a sheet with a bunch of airline names, there may be more than
of the same airline in the same column. What I've been able to do s
far is make an array and have it hold all the unique airline names.
want to then populate the listbox on a form with these airlines so th
user can select as many airlines as he wants to do some mor
calculations.

So basically I'm not sure how to write code for the listbox to make i
retrieve the data from the array.

Hope I explained it properly. Any suggestions are welcome. Thanks
bunch.

Coli
 
J

Jim Thomlinson

Without seeing any of your code this will have to be kind of generic. It
should look something like this...

sub PopulateListBox(byval MyArray() as string)
dim intCounter as integer

listbox1.clear
for intcounter = lbound(MyArray) to ubound(myArray)
listbox1.additem myArray(intcounter)
next intcounter
end sub
 
S

shenlingstyle

Thanks so much for the help guys, it worked!! I have one further
question:

How do I determine which items (I enabled multiselect) are selected in
the listbox and put these selected items (the names of airilnes) into
another array?

Thanks again!
 
T

Tom Ogilvy

dim v as Variant
dim i as long, k as Long
Redim v(0 to Listbox1.Listcount-1)
k = -1
for i = 0 to Listbox1.Listcount - 1
if listbox1.selected(i) then
k = k + 1
v(k) = listbox1.List(i)
end if
Next
Redim Preserve v(0 to k)

--
Regards,
Tom Ogilvy


"shenlingstyle" <[email protected]>
wrote in message
news:[email protected]...
 
M

MikeF

I actually have a question .. what method did you engage to get the array to
hold unique names?

Thanx.
- Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top