Can't populate combobox list with 1 item

S

Steph

Hi. I am populating combobox lists with the following code:

UserForm1.ComboBox1.List =
Price.Range("LMU").Resize(Price.Range("LMU").Rows.Count - 1).Value

I have the ranges set up as named ranges, but for other purposes, i have a
blank cell as the last cell in each range. So in order to remove that from
the list, I am using the Count-1. This works great until I get to a range
that has only line in it (well, 2 lines - one populated and then the one
blank line).

When I run this, I get an error 381 - so apparently the combobox will not
allow me to populate it's list with only 1 selection?? Is there any way
around this??

Thanks so much!
 
F

Frank Kabel

Hi
use the additem method of your combobox. e.g.
UserForm1.ComboBox1.additem
Price.Range("LMU").Resize(Price.Range("LMU").Rows.Count - 1).Value
 
S

Steph

Thanks Frank!! Much appreciated.

Frank Kabel said:
Hi
use the additem method of your combobox. e.g.
UserForm1.ComboBox1.additem
Price.Range("LMU").Resize(Price.Range("LMU").Rows.Count - 1).Value
 
S

Steph

Frank,

Worked great for the single entries. But errored when I applied the same
code to all comboboxes - most of which have more than one entry. The
problem I'll have is the list that I need populated in the comboboxes are
dynamic and can be increased by the end user. So a list that now only has
one entry could very well have 2 tomorrow. Can I somehow take both into
account?
 
F

Frank Kabel

Hi
you have to create a loop and 'add' each single entry with additem. So
loop through your list of values and add them to your combobox (I think
the VBA help shows this for additem)
 
Top