VBA Combobox dependent on another Combobox...

Charmwah

Board Regular
Joined
Jan 23, 2017
Messages
64
Hi all

I have a simple userform (CustomerByProduct), where the user must make a selection from the 1st Combobox (cmdProductFamily, with the idea being that this choice then determines the options shown in the 2nd Combobox (cmdProductName). The choice from the 1st relates to a named range of the same name. However, I can't get the 2nd Combobox list to populate with the code i'm using, and I can't work out where i'm going wrong...

Code:
Option Explicit
Private Sub cmdProductFamily_Change()
    If Me.cmdProductFamily.Value = "AA" Then Me.cmdProductName.RowSource = "AA"
    If Me.cmdProductFamily.Value = "BB" Then Me.cmdProductName.RowSource = "BB"
End Sub
Sub ShowDialogBox()
    CustomerByProduct.Show
End Sub

I also tried it the other way around, and that didn't help...

Code:
Option Explicit
Private Sub cmdProductName_Change()
    If Me.cmdProductFamily.Value = "AA" Then Me.cmdProductName.RowSource = "AA"
    If Me.cmdProductFamily.Value = "BB" Then Me.cmdProductName.RowSource = "BB"
End Sub
Sub ShowDialogBox()
    CustomerByProduct.Show
End Sub

The RowSource property box for the 2nd Combobox is blank.

I'm a relative noob, so its sure to be a simple error, but any help greatly appreciated!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try
Code:
Private Sub cmdProductFamily_Change()
   If Me.cmdProductFamily.Value = "AA" Then Me.cmdProductName.RowSource = Range("AA").Address
   If Me.cmdProductFamily.Value = "BB" Then Me.cmdProductName.RowSource = Range("BB").Address
End Sub
 
Upvote 0
Hi Fluff

That didn't work either i'm afraid. I've attached the link here in case it helps?

Try
Code:
Private Sub cmdProductFamily_Change()
   If Me.cmdProductFamily.Value = "AA" Then Me.cmdProductName.RowSource = Range("AA").Address
   If Me.cmdProductFamily.Value = "BB" Then Me.cmdProductName.RowSource = Range("BB").Address
End Sub
 
Upvote 0
That code needs to go in the userform module, not a regular module.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
@Fluff

Help please!!!

Have adapted your code above to ...

VBA Code:
Private Sub cboStrategyAlignment_Change()
   If cboStrategyAlignment.value = "Engagement" Then cboSpokeFocus.RowSource = Sheets("Look Up Tables").Range("Engagement").Address
   If cboStrategyAlignment.value = "Efficiency" Then cboSpokeFocus.RowSource = Sheets("Look Up Tables").Range("Efficiency").Address
   If cboStrategyAlignment.value = "Improvement" Then cboSpokeFocus.RowSource = Sheets("Look Up Tables").Range("Improvement").Address
End Sub

... which works perfectly if the active worksheet is Look Up Tables ...

But I need the code to work when the active worksheet is another worksheet in the same workbook - I thought adding Sheets("Look Up Tables"). infront of Range would do it, but it doesn't!

What am I missing?

Thanks ...
 
Upvote 0
@Fluff

PS; have also tried Worksheets("Look Up Tables"). but that doesn't work either?!!!
 
Upvote 0
@Fluff

Got it ...

VBA Code:
Private Sub cboStrategyAlignment_Change()

With Sheets("Look Up Tables")
   If cboStrategyAlignment.value = "Engagement" Then cboSpokeFocus.List = .Range("Engagement").value
   If cboStrategyAlignment.value = "Efficiency" Then cboSpokeFocus.List = .Range("Efficiency").value
   If cboStrategyAlignment.value = "Improvement" Then cboSpokeFocus.List = .Range("Improvement").value
End With

End Sub

... unless there's a better way?

Thanks ...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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