Reputation: 3897
The value of the textbox needs to be dependent on the value of the dropdown-list.
e.g. When an industry category is selected, the corresponding industry code should appear in the textbox.
Column A (Industry Category):
Agriculture
Art and photography
Arts and theatre
Charity and non-profit
Corporate
Educational and academic
Column B (Industry Specifier):
ag
ap
at
cn
co
ea
Populating the dropdown list for industry category:
'Populate Industry combo box.
Dim range_c As Range
Dim ws_c As Worksheet
Set ws_c = Worksheets("4.1 List data")
For Each range_c In ws_c.Range("IndustryList")
With Me.Industry
.AddItem range_c.Value
.List(.ListCount - 1, 1) = range_c.Offset(0, 1).Value
End With
Next range_c
Textbox for industry specifier:
IndustrySpecifier.Value = ""
I've reviewed tutorials on how to achieve what I need using VBA code alone but I don't know where to begin using dependent named ranges
Upvotes: 4
Views: 10584
Reputation: 35853
You need something like this:
Private Sub UserForm_Initialize()
Dim range_c As Range
For Each range_c In Worksheets("4.1 List data").Range("IndustryList")
With Me.Industry
.AddItem range_c.Value
.List(.ListCount - 1, 1) = range_c.Offset(0, 1).Value
End With
Next range_c
End Sub
Private Sub Industry_Change()
With Me.Industry
If .ListIndex = -1 Then
IndustrySpecifier.Text = ""
Else
IndustrySpecifier.Text = .List(.ListIndex, 1)
End If
End With
End Sub
Upvotes: 4