问题
Form will accept information and then copy the info to Sheet1. The form contains 5 textbox and 2 combobox. 1st combobox options are CRIS, TRACS, and DOCS. 2nd combobox option should be based on the 1st combobox selection.
Here's my code so far:
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
回答1:
add this code in your userform code pane:
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
来源:https://stackoverflow.com/questions/39927694/excel-combobox-dropdown-items-based-on-the-previous-combobox