Listbox with cloumns

  • Thread starter Thread starter Stuart Holley
  • Start date Start date
S

Stuart Holley

I need to get an unknown quantity of items into a list box that has
two columns.

ie

sheet

a1 a2
b1 b2
c1 c2


would like to get list box to display

a1, a2
b1, b2
c1, c2
etc....

I can get one item or both if I add the data together but then I need
to do a lot of fiddling around to seperate it when I have selected it.
What I would like to use is something like

requestedtext = listbox1.list(3,2)

but I can get the data into the list box in the first place.....


Many thanks

Stuart
 
Hi Stuart,

You can do this a few different ways. One of the easiest ways
programmatically-speaking (IMO) would be to do the following:

1) Create a dynamic named range that refers to your data:

a. Insert | Names | Define...
b. Type in the name you wish to define (eg, rngListSource)
c. Use the following formula for the Refers To box:

=OFFSET(Sheet1!$A$1, 0, 0, COUNTA(Sheet1!$A:$A), 2)

d. Click Add, then Close

2) Set the ColumnCount property of the ListBox to 2 (at design time).

3) Set the RowSource property of the ListBox to rngListSource (at design
time).

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Set the ColumnCount property to 2, and add the details like so

With Me.ListBox1
.AddItem "Bob"
.List(.ListCount - 1, 1) = "M"
.AddItem "Lynne"
.List(.ListCount - 1, 1) = "F"
End With

or simply set up the data in a 2D table, and point the Rowsource property at
that table.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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

Back
Top