Combo Box VBA code ?

Javi

Active Member
Joined
May 26, 2011
Messages
440
Hi All,

I have one combo box supplying the row source to another combo box. I am using define range in the first combo box to achieve this. Everything is working well except for when combobox1 is blank or does not have a matching named range.

Combo box 1 has a row source of sheet1!A2:A33. the data in the Cells sheet1!A2:A33 has a range match for each of the 31 line items.

When I select an item and combobox1 it supplies combobox2 with the corresponding defined range, works great except the code below does not allow for combobox1 to be blank or have a nonmatching value.


I'm looking to achieve two things.

Have combobox1 with no value have the same result in combobox2 no value .
Have combobox1 to have a value without a corresponding defined range then leave combobox2 blank.

In the current state if either of the two occur the code fails.

Thank you in advance for any help or assistance.


Code:
Private Sub ComboBox1_Change()
 
 
Me.ComboBox2.Value = ""
 

Me.ComboBox2.RowSource = Me.ComboBox1.Value

If Me.ComboBox1.Value = "" Then


Exit Sub
End If
 
 
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I did forget to mention, I'm using these two combo boxes in a user form.

I'm hoping I did not make a simple request to complicated sorry for being so wordy.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top