Populating ComboBoxes

W

WIlliam Barnes

I'm trying to populate a combobox control with items from a Range on a
worksheet. I have code that returns a Variant assigned to a Range of cells
in a WorkSheet. Is there an easy way to assign these values to the ComboBox,
or must I loop through the Variant array? I tried assigning the ComboBox
RowSource Property to the Variant but got an error. My code looks something
like this:

Public Function GetData() as Variant
Dim rng as Range
Set rng = MyWorkSheet.Range("$A$1:$E$1")
GetData = rng
End Function

Private Sub MyForm_Initialize()
ComboBox1.RowSource = GetData
End Sub
 
B

Bob Phillips

William,

The Rowsource property is a string, so either return a string in the
function (rng.Address), or do it the form initialise (ComboBox1.RowSource =
GetData.Address )

--

HTH

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

WIlliam Barnes

Thanks Bob. That's what it took.

Bob Phillips said:
William,

The Rowsource property is a string, so either return a string in the
function (rng.Address), or do it the form initialise (ComboBox1.RowSource =
GetData.Address )

--

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

Top