View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default ComboBox Hell!!!

The simple code you show should work:

ComboBox1.List = Worksheets("Sheet1").Range("A1:A10").Value

or

ComboBox1.RowSource = "Sheet1!A1:A10"

or

Dim cell As Range
For Each cell In Worksheets("Sheet1").Range("A1:A10")
ComboBox1.AddItem cell.Value
Next cell

You should put one of these approaches in the initialize event of the
userform. By the way, copying the controls from a worksheet to a userform
doesn't seem necessary. You can just use the controls from the control
toolbox and place them on the form in the VBE - this takes much less time,
even if you have to change a few properties.

When specifing the listfillrange or the rowsource, include the sheet name:
Sheet1!A1:A10 this avoids the problems you were having. For a
multicolumn combobox or listbox, set the columncount property.

--
Regards,
Tom Ogilvy



"Dave Baranas" wrote in message
...
Hi , I am having a terrible time getting a combobox to fill up now
that I have moved everything from a WorkSheet to a UserForm

When they were on a worksheet everything was fine as I could just use

ComBoBox.ListFillRange = ("A1:A10)

As long as my list was on the same sheet. I never got this to work
tryimg to load a list from another sheet ( and I tried the examples
from here but no luck, but I could live with that) So I changed my bad
design of lots of sheets to just a few and a master data sheet so I
could read and write from it...and life was good

So I try to go a step further and put all the controls on a nice user
form from a worksheet and spend hours because you can only drag and
drop them one at a time from a worksheet to a form and rename them
all. But thats OK too....cause I am going to be almost done I think

Now I can only fill a combobox by changing its properties in the form.
I tried these examples from an earlier post here and none of them
work. I have to show 2 columns in some and now this does not work
anymore because now the comboboxes are on a form instead of a
worksheet where I could get them to work either by changing object
properties or using VBA

Is there something so insanely stupid I am not seeing from lack of
sleep or can you really fill a combobox on a form using VBA code
instead of clicking on every one of these $%&^*(# things to get them
to fill up.

ThanksInAdvanceDaveBaranas

Using Excel 2002
--------------------------------------------------------------------------

-----------------------------------------

ComboBox1.List = Worksheets("Sheet1").Range("A1:A10").Value

or

ComboBox1.RowSource = "Sheet1!A1:A10"

or

Dim cell As Range
For Each cell In Worksheets("Sheet1").Range("A1:A10")
ComboBox1.AddItem cell.Value
Next cell

For more info on comboboxes/listboxes see
www.rubbershoe.com/listbox.htm