2017-11-03 106 views
0

我有兩個組合框,第一個選擇第二個顯示的組合框。第一個選擇什麼,第二個應該顯示兩列。在選擇上一個組合框以確定數據後,填充多列組合框和工作表數據

我有它運行在第二個組合框中一列與

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 indexList(.ListCount - 1, 1) = strRange線。

就像我說的,我嘗試了很多東西,但是我沒有超過這個。

回答

0

在爲其分配值之前,您需要將項目添加到列表中。添加的項目成爲第0列。

With cbo_asset 
     .ColumnCount = 2 
     .ColumnWidths = "60pt;75pt;" 
     .RowSource = vbNullString 
     .AddItem strRange 
     .list(.ListCount - 1, 1) = strRange2 
     .ListIndex = 0 
    End With 
+0

感謝分配回來這個。我已經嘗試過它,它可以工作,現在我可以將它用於其他事情...... –