Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim WshShell, EE
Dim intLen As Integer
On Error Resume Next
If KeyCode = 13 Then
If Len(Me.TextBox1.Text) And Len(Me.TextBox1.Text) <> 16 Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.popup "※字數不正確,請重新輸入!", 1, ""
Else
If Me.Controls("TextBox1") <> "" Then
If Me.Controls("TextBox1") = Me.Controls("TextBox2") Then GoTo EE
bcr = True
Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 2) = TextBox1.Text
Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 3) = TextBox2.Text
Cells(Cells(Rows.Count, 1).End(xlUp).Row + 1, 1) = Date
ElseIf bcr = True Then
bcr = False
Else
End If
End If
End If
If KeyCode = 13 Then CommandButton1_Click
Exit Sub
EE: MsgBox WshShell.popup
Set WshShell = CreateObject("WScript.Shell")
EE = WshShell.popup(BtnCode, 1, "重複", 16)
If KeyCode = 13 Then CommandButton1_Click
End Sub
Private Sub CommandButton1_Click()
r = Len(Me.TextBox1.Text)
Me.TextBox1.SetFocus
Me.TextBox1.SelStart = 0
Me.TextBox1.SelLength = r
KeyCode = 13
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r&, i&
If Target.Column = 2 And Target.Count = 1 Then
r = Target.Row
i = Application.CountIf(Range("B1:B" & r), Target.Value)
If i > 1 Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.popup Target.Value & "重複,請重新輸入!", 1, ""
End If
End If
If Target.Column = 3 And Target.Count = 1 Then
r = Target.Row
i = Application.CountIf(Range("C1:C" & r), Target.Value)
If i > 1 Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.popup Target.Value & "重複,請重新輸入!", 1, ""
End If
End If
End Sub
各位前輩們,自己拼湊完成了一個掃描槍的程式,但現在出現一個問題,就是掃描,記錄到欄位後,會出現重複訊息的問題,應該是超過16碼的問題吧,請問有解嗎?謝謝