Userform ComboBox based on another ComboBox

tdahlman

New Member
Joined
Apr 11, 2014
Messages
14
I have a userform with 2 Combo Boxes (cbCategory and cbSubCategory).

cbCategory is is populated based on the named range "categories" consisting of Income, Home, Daily Living, Transportation, Health & Recreation, Vacation, Dues & Subscriptions, Debts, Savings, and Misc.

Based on the selection in cbCategory I want cbSubCategory to populate with the appropriate named rage:
- Income = "Income"
- Home = "Home"
- Daily Living = "Daily"
- Transportation = "Transport"
- Health & Recreation = "Health"
- Vacation = "Vacation"
- Dues & Subscriptions = "Dues"
- Debts = "Debts"
- Savings = "Savings"
- Misc = "Misc"

I have my code figured out for the UserForm_Initialize() so that my userform is cleared and the cbCategory is populated with the named range "categories".
Now I just need to figure out my code for cbCategory_Change() to use the correct named range based on the cbCategory selection.

Any help or direction would be greatly appreciated.

Thanks,
Travis
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,
you could try adding your range names to an array & then access the array elements to return range name by using the combobox listindex property. Something like this:

Code:
Dim myarray()
Private Sub cbCategory_Change()
    With Me.cbSubCategory
        .Clear
        .List = _
        Range(myarray(Me.cbCategory.ListIndex)).Value
        .ListIndex = 0
    End With
End Sub

Private Sub Userform_Initialize()
    Dim i As Integer
    Dim RangeName As Variant
    
    i = 0
    For Each RangeName In ThisWorkbook.Names
        'Named ranges
        If RangeName.Name <> "categories" Then
            ReDim Preserve myarray(i)
            myarray(i) = RangeName.Name
            i = i + 1
        End If
    Next RangeName
    
    Me.cbCategory.List = myarray
    
End Sub


Hope Helpful

Dave
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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