文本框的值需要取决于下拉列表的值。
e.g。选择 行业类别 后,相应的 行业代码 应出现在文本框中。
A栏( 行业类别 ):
Agriculture
Art and photography
Arts and theatre
Charity and non-profit
Corporate
Educational and academic
B栏( 行业规范 ):
ag
ap
at
cn
co
ea
填充 行业类别 的下拉列表:
'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
行业说明符的文本框:
IndustrySpecifier.Value = ""
我已经查看了有关如何仅使用VBA代码实现所需内容的教程,但我不知道从哪里开始使用相关命名范围
答案 0 :(得分:4)
你需要这样的东西:
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