Filling a List Box in Excel from an Array

G

Guest

Hope someone can help. I have a listbox in excel which I am trying to
populate from an array. The array is picking up certain values from a sheet
depending on a previous value selected in another list box. I currently have
the array code in a module.

regards,
Martin
 
B

Bob Phillips

As an example

For i = LBound(ary) To UBound(ary)
Listbox1.AddItem ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
A

Andy Pope

Another example.

Dim strArray(2) As String

strArray(0) = "X"
strArray(1) = "Y"
strArray(2) = "Z"
ListBox1.List = strArray

Cheers
Andy
 
G

Guest

Hi Bob,

I have done the below but having read other threads is it not possible to
create a dropdown in a worksheet using the control box and then add items
using VBA?? I am having to reference the control as follows

worksheets("Main").shapes("List Box 2").AddItem UniArray(transnumber)

I get an 'Object does not support property or method' runtime error. Is the
only way around this to create a dropdown via code?
 
B

Bob Phillips

Martin,

If you added the control from the controls toolbox, you need to use

worksheets("Main").ListBox2.AddItem UniArray(transnumber)

or

worksheets("Main").oleobjects("ListBox2").object.AddItem
UniArray(transnumber)



--

HTH

RP
(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

Top