Excelcombobox下拉项目基于以前的combobox

表单将接受信息,然后将信息复制到Sheet1。 该表格包含5个文本框和2个combobox。 第一个combobox选项是CRIS,TRACS和DOCS。 第二个combobox选项应该基于第一个combobox的select。

表单设计

这是我的代码到目前为止:

Private Sub cmdClear_Click() Call UserForm_Initialize End Sub Private Sub cmdMove_Click() Dim emptyRow As Long Sheet1.Activate 'Make Sheet1 active emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 'Transfer information Cells(emptyRow, 1).Value = txtName.Value Cells(emptyRow, 2).Value = txtBtn.Value Cells(emptyRow, 3).Value = txtCbr.Value Cells(emptyRow, 4).Value = txtOrder.Value Cells(emptyRow, 5).Value = txtTrouble.Value Cells(emptyRow, 6).Value = ComboBox1.Value End Sub Private Sub UserForm_Click() End Sub Private Sub UserForm_Initialize() txtName.Value = "" 'Empty NameTextBox txtBtn.Value = "" 'Empty BTN txtCbr.Value = "" 'Empty CBR txtOrder.Value = "" 'Empty Order Number txtTrouble.Value = "" 'Empty Trouble Ticket Number ComboBox1.Clear With ComboBox1 .AddItem "CRIS" .AddItem "TRACS" .AddItem "DOCS" End With txtName.SetFocus End Sub 

将这些代码添加到您的用户表单代码窗格中:

 Private Sub ComboBox1_Change() With Me If .ComboBox1.ListIndex <> -1 Then Select Case .ComboBox1.Value Case "CRIS" .ComboBox2.List = Array("close", "reroute", "transfer") Case "TRACS" .ComboBox2.List = Array("close", "reroute") Case "DOCS" .ComboBox2.List = Array("completed", "transfer", "update") End Select End If End With End Sub