在此处继续我的上一个问题 - Excel combobox dropdown items based on the previous combobox
我为CRIS,TRACS,DOCS和TOTAL添加了4个TextBox。 我希望有一个可见的计数器,根据我在ComboBox1中选择的选项进行填充Tracker
Private Sub cmdBack_Click()
Unload Me
frmLogin.Show
End Sub
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 'Determine emptyRow
'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
Cells(emptyRow, 7).Value = ComboBox2.Value
End Sub
Private Sub ComboBox1_Change()
Select Case ComboBox1.Text
Case "TRACS"
With ComboBox2
.Clear
.AddItem "Complete"
.AddItem "Re-Route"
End With
Case "CRIS"
With ComboBox2
.Clear
.AddItem "Close"
.AddItem "Re-route"
.AddItem "Transfer"
End With
Case "DOCS"
With ComboBox2
.Clear
.AddItem "Completed"
.AddItem "Follow-up"
.AddItem "Reject"
End With
End Select
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
ComboBox2.Clear
With ComboBox1
.AddItem "CRIS"
.AddItem "TRACS"
.AddItem "DOCS"
End With
txtName.SetFocus
End Sub
答案 0 :(得分:0)
我会做一些不同的事情:
Private Sub cmdBack_Click()
Unload Me
frmLogin.Show
End Sub
Private Sub cmdClear_Click()
txtName.Value = "" 'Empty NameTextBox
txtBtn.Value = "" 'Empty BTN
txtCbr.Value = "" 'Empty CBR
txtOrder.Value = "" 'Empty Order Number
txtTrouble.Value = "" 'Empty Trouble Ticket Number
ComboBox2.Clear
ComboBox1.ListIndex = -1
txtName.SetFocus
End Sub
Private Sub cmdMove_Click()
With Sheet1
With .Range("A" & .Rows.Count).End(xlUp)
.Offset(1).Resize(1, 7).Value = Array(txtName.Value, txtBtn.Value, txtCbr.Value, txtOrder.Value, txtTrouble.Value, ComboBox1.Value, ComboBox2.Value)
End With
txtCRIS.Value = Application.CountIf(.Columns(6), "CRIS")
txtTRACS.Value = Application.CountIf(.Columns(6), "TRACS")
txtDOCS.Value = Application.CountIf(.Columns(6), "DOCS")
txtTotal.Value = Application.Sum(txtCRIS.Value, txtTRACS.Value, txtDOCS.Value)
End With
End Sub
Private Sub ComboBox1_Change()
Select Case ComboBox1.Text
Case "TRACS"
ComboBox2.List = Array("Complete", "Re-Route")
Case "CRIS"
ComboBox2.List = Array("Close", "Re-route", "Transfer")
Case "DOCS"
ComboBox2.List = Array("Completed", "Follow-up", "Reject")
End Select
End Sub
Private Sub UserForm_Initialize()
ComboBox1.List = Array("CRIS", "TRACS", "DOCS")
txtName.SetFocus
End Sub