Dropdown list on a form - values dependent on another dropdown on the form?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
I hope I can explain this properly.

I have a dropdown (combi?) box on a form called cmb_repcat and this contains a list of items (reporting categories) where the user needs to select one.

There is then another dropdown (combi?) box on the form called cmb_repsubcat - this contains a list of items (sub-reporting categories). I want this box to be populated only with items relevant to what is selected in the first dropdown.

So for example, if "Income" were selected in box 1, I wouldn't want the user to be able to select "Cost Of sales" from box 2 because that isn't income.

Any help appreciated, thank you for reading.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
you can create tables for each sub-category & use the controls listindex property to access the required table.

02-06-2023.xls
DEFGH
1Sub-Category 1Sub-Category 2Sub-Category 3
2Sub Category 1 -1Sub Category 2 -1Sub Category 3 -1
3Sub Category 1 -2 Sub Category 2 -2 Sub Category 3 -2
4Sub Category 1 -3Sub Category 2 -3Sub Category 3 -3
5Sub Category 1 -4Sub Category 2 -4Sub Category 3 -4
6Sub Category 1 -5Sub Category 2 -5Sub Category 3 -5
7Sub Category 1 -6Sub Category 2 -6Sub Category 3 -6
8Sub Category 1 -7Sub Category 2 -7Sub Category 3 -7
9Sub Category 1 -8Sub Category 2 -8Sub Category 3 -8
10Sub Category 1 -9Sub Category 2 -9Sub Category 3 -9
Sheet1


code for the cmb_repcat control

VBA Code:
Private Sub cmb_repcat_Change()
    Dim tbl     As ListObject
    Dim index As Long
    
    index = Me.cmb_repcat.ListIndex + 1
    If index = 0 Then Me.cmb_repsubcat.Clear: Exit Sub
    
    Set tbl = Worksheets("Sheet1").ListObjects(index)
    Me.cmb_repsubcat.List = tbl.DataBodyRange.Value
    
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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