ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Populating a listbox with values from a sheet. (https://www.excelbanter.com/excel-programming/346165-populating-listbox-values-sheet.html)

shenlingstyle[_2_]

Populating a listbox with values from a sheet.
 

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

--
shenlingstyl
-----------------------------------------------------------------------
shenlingstyle's Profile: http://www.excelforum.com/member.php...fo&userid=2767
View this thread: http://www.excelforum.com/showthread.php?threadid=48688


Jim Thomlinson[_4_]

Populating a listbox with values from a sheet.
 
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
--
HTH...

Jim Thomlinson


"shenlingstyle" wrote:


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

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

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

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

Colin


--
shenlingstyle
------------------------------------------------------------------------
shenlingstyle's Profile: http://www.excelforum.com/member.php...o&userid=27672
View this thread: http://www.excelforum.com/showthread...hreadid=486888



Tom Ogilvy

Populating a listbox with values from a sheet.
 
Activeworksheet.Listbox1.List = vArray

--
Regards,
Tom Ogilvy

"shenlingstyle"
wrote in message
news:shenlingstyle.1yuw9y_1132592403.3273@excelfor um-nospam.com...

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

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

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

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

Colin


--
shenlingstyle
------------------------------------------------------------------------
shenlingstyle's Profile:

http://www.excelforum.com/member.php...o&userid=27672
View this thread: http://www.excelforum.com/showthread...hreadid=486888




shenlingstyle[_3_]

Populating a listbox with values from a sheet.
 

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!


--
shenlingstyle
------------------------------------------------------------------------
shenlingstyle's Profile: http://www.excelforum.com/member.php...o&userid=27672
View this thread: http://www.excelforum.com/showthread...hreadid=486888


Tom Ogilvy

Populating a listbox with values from a sheet.
 
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"
wrote in message
news:shenlingstyle.1yv07m_1132597502.1446@excelfor um-nospam.com...

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!


--
shenlingstyle
------------------------------------------------------------------------
shenlingstyle's Profile:

http://www.excelforum.com/member.php...o&userid=27672
View this thread: http://www.excelforum.com/showthread...hreadid=486888




MikeF[_2_]

Populating a listbox with values from a sheet.
 

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

Thanx.
- Mike

"shenlingstyle" wrote:


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

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

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

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

Colin


--
shenlingstyle
------------------------------------------------------------------------
shenlingstyle's Profile: http://www.excelforum.com/member.php...o&userid=27672
View this thread: http://www.excelforum.com/showthread...hreadid=486888




All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com