Private Sub CommandButton1_Click()
Dim T$, T1$, T2$, R&
T1 = TextBox1: T2 = TextBox2: T = T1 & "|" & T2
If T1 = "" Then MsgBox "你必須輸入 (車輛編號) ": Exit Sub
If T2 = "" Then MsgBox "你必須輸入 (司機人員) ": Exit Sub
R = Val(vD(T))
If R = 0 Then MsgBox "車輛/司機:" & T1 & "/" & T2 & ",這組合不存在 ": Exit Sub
If R < 0 Then '出車
Cells(-R, 3).Resize(1, 4) = ""
Cells(-R, 4) = Now: ComboBox1.Text = ""
vD(T) = -R
Else '回車
If ComboBox1.Text = "" Then MsgBox "這是【回車】趟,(回車物品) 必須輸入 ": Exit Sub
Cells(R, 3) = T2: Cells(R, 5) = Now: Cells(R, 6) = ComboBox1.Text
vD(T) = -R
End If
End Sub
Private Sub UserForm_Initialize()
Dim T$, T1$, T2$, i&
Set vD = CreateObject("Scripting.Dictionary")
Arr = Range([F1], [A65536].End(xlUp))
For i = 2 To UBound(Arr)
T1 = Arr(i, 1): T2 = Arr(i, 2): T = T1 & "|" & T2
If T1 = "" Or T2 = "" Then GoTo 101
vD(T) = i
If Arr(i, 4) = "" Or Arr(i, 5) <> "" Then vD(T) = -i
101: Next i
ComboBox1.List = Array("NO", "Yes")
End Sub
Private Sub CommandButton1_Click()
Dim T$, T1$, T2$, R&
T1 = TextBox1: T2 = TextBox2: T = T1 & "|" & T2
If T1 = "" Then MsgBox "你必須輸入 (車輛編號) ": Exit Sub
If T2 = "" Then MsgBox "你必須輸入 (司機人員) ": Exit Sub
R = Val(vD(T))
If R = 0 Then '出車
R = [A:A].Find(What:="", LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext).Row
Cells(R, 1) = T1: Cells(R, 2) = T2: Cells(R, 4) = Now
vD(T) = R
Else '回車
If ComboBox1.Text = "" Then MsgBox "這是【回車】趟,(回車物品) 必須輸入 ": Exit Sub
Cells(R, 3) = T2: Cells(R, 5) = Now: Cells(R, 6) = ComboBox1.Text
vD(T) = 0
End If
TextBox1 = "": TextBox1.SetFocus: TextBox2 = "": ComboBox1 = ""
End Sub
Private Sub UserForm_Initialize()
Dim T$, T1$, T2$, i&, Arr
Set vD = CreateObject("Scripting.Dictionary")
Arr = Range([F1], [A65536].End(xlUp))
For i = 2 To UBound(Arr)
T1 = Arr(i, 1): T2 = Arr(i, 2): T = T1 & "|" & T2
If T1 <> "" And T2 <> "" And Arr(i, 3) = "" Then vD(T) = i
Next i
ComboBox1.List = Array("NO", "Yes")
End Sub