表单将接受信息,然后将信息复制到Sheet1。 该表单包含5个文本框和2个组合框。第一个组合框选项是CRIS,TRACS和DOCS。第二个组合框选项应基于第一个组合框选择。
到目前为止,这是我的代码:
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
答案 0 :(得分:1)
在您的用户窗体代码窗格中添加此代码:
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