我目前正在为客户处理 Excel 电子表格中的表格。
下拉列表需要从lookupDept工作簿的两列中提取信息并合并。例如我有:
deptCode deptName
BS Business School
CD Design and Technology
CG Chemical Engineering
CM Chemistry
CO Computer Science
这需要出现在下拉列表中
BS - Business School
CD - Design and Technology
CG - Chemical Engineering
CM - Chemistry
CO - Computer Science
这是我目前正在使用的代码,不幸的是它似乎不起作用并返回Compile Error: Invalid Next control variable reference。这是我到目前为止使用的代码:
Private Sub UserForm_Initialize()
Dim c_deptCode As Range
Dim c_deptName As Range
Dim ws_dept As Worksheet
Set ws_dept = Worksheets("lookupDept")
For Each c_deptCode In ws_dept.Range("deptCode")
With Me.cbo_deptCode
.AddItem c_deptCode.Value
.List(.ListCount - 1, 1) = c_deptCode.Offset(0, 1).Value
End With
Next c_deptCode
For Each c_deptName In ws_dept.Range("deptName")
With Me.cbo_deptCode
.AddItem c_deptName.Value
End With
Next cLoc
End Sub
提前致谢!