Populate userform combobox with option button

G

Gig

I have a simple userform with a combox and two option buttons. I would
like to populate the combobox with a range if optionbutton1 is clicked
and with another range if ob2 is clicked. I keep getting a "Run time
error 13, type mismatch" message. My code is below.

Private Sub OptionButton1_Click()
UserForm1.ComboBox1.RowSource = Range("a1:a10")
End Sub

Can anyone tell me what is wrong with this? Looks legit to me.

Thanks for any help,
Greg
 
O

OssieMac

Hi Greg,

These properties are set as strings that look idnetical to the way you would
enter them in the properties dialog box.

Private Sub OptionButton1_Click()
UserForm1.ComboBox1.RowSource = "Sheet1!A1:A10"
End Sub

Private Sub OptionButton2_Click()
UserForm1.ComboBox1.RowSource = "Sheet1!B1:B10"
End Sub
 
G

gig4g4b

Hi Greg,

These properties are set as strings that look idnetical to the way you would
enter them in the properties dialog box.

Private Sub OptionButton1_Click()
     UserForm1.ComboBox1.RowSource = "Sheet1!A1:A10"
End Sub

Private Sub OptionButton2_Click()
     UserForm1.ComboBox1.RowSource = "Sheet1!B1:B10"
End Sub

Thanks Ossie, but can you tell me why the code wouldn't be written
like this:

Private Sub OptionButton2_Click()
UserForm1.ComboBox1.RowSource = Sheets("sheet1").range("B1:B10")
End Sub

Thanks,
Greg
 
O

OssieMac

Hi Greg,

I can't really explain more than my previous comment "These properties are
set as strings that look identical to the way you would enter them in the
properties dialog box."
Bacically the code emulates what you would do manually.
 

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