在选择上一个组合框以确定数据后,填充多列组合框和工作表数据
问题描述:
我有两个组合框,第一个选择第二个显示的组合框。第一个选择什么,第二个应该显示两列。在选择上一个组合框以确定数据后,填充多列组合框和工作表数据
我有它运行在第二个组合框中一列与
Private Sub cbo_area_Change()
'Populate Equipment combo box.
Dim strRange As String
If cbo_area.ListIndex > -1 Then
strRange = cbo_area
Label2.Caption = strRange
strRange = Replace(strRange, " ", "_")
With cbo_asset
.RowSource = vbNullString
.RowSource = strRange
.ListIndex = 0
End With
End If
End Sub
,现在大量的研究和尝试各种事情之后,我曾尝试以下,以获得两列。
Private Sub cbo_area_Change()
'Populate Equipment combo box.
Dim strRange As String
Dim strRange2 As String
If cbo_area.ListIndex > -1 Then
strRange = cbo_area
Label2.Caption = strRange
strRange = Replace(strRange, " ", "_")
strRange2 = strRange & "2"
With cbo_asset
.RowSource = vbNullString
.List(.ListCount - 1, 1) = strRange
.List(.ListCount - 1, 2) = strRange2
.ListIndex = 0
End With
End If
End Sub
但我得到一个invalid property array index
在List(.ListCount - 1, 1) = strRange
线。
就像我说的,我尝试了很多东西,但是我没有超过这个。
答
在为其分配值之前,您需要将项目添加到列表中。添加的项目成为第0列。
With cbo_asset
.ColumnCount = 2
.ColumnWidths = "60pt;75pt;"
.RowSource = vbNullString
.AddItem strRange
.list(.ListCount - 1, 1) = strRange2
.ListIndex = 0
End With
感谢分配回来这个。我已经尝试过它,它可以工作,现在我可以将它用于其他事情...... –