Private Sub CommandButton1_Click()
Sheet2.Visible = True
Sheets("交接事項").Activate
Dim UserId As String
Dim N As Long
Dim FD As Range
Set FD = Range("a65536").End(xlUp).Offset(1, 0)
Dim Ar, a1, i% '此處宣告3個欄位
a1 = TextBox1
Ar = Array(a1) '欄位儲存於陣列
UserId = TextBox1.Value
If UserId = "" Then
MsgBox "請輸入ID"
GoTo 101
End If
For N = 1 To 300
If Sheet3.Cells(N, 5).Value = UserId Then
If Sheet3.Cells(N, 6).Value = TextBox2.Value Then
MsgBox "登入成功"
if a1 <> "" Then '判斷所有值都不等於空白
i = 2 '第一列開始
Do Until Cells(i, 1) = "" 'A欄為空白則停止迴圈
i = i + 1 '向下一列
Loop
Cells(i, 3).Resize(, 1) = Ar 'A欄空白向右擴展成欄位數量
FD = Date '往右一格寫入當前時間
FD.Offset(0, 1) = Time '往右二格寫入txtID的資料
End If
UserForm1.Hide
GoTo 101
Else
MsgBox "登入失敗"
i = 2 '第一列開始
Do Until Cells(i, 1) = "" 'A欄為空白則停止迴圈
i = i + 1 '向下一列
Loop
Cells(i, 10).Resize(, 1) = Ar 'A欄空白向右擴展成欄位數量
FD.Offset(0, 8) = Date '往右一格寫入當前時間
FD.Offset(0, 9) = Time '往右二格寫入txtID的資料
Private Sub CommandButton2_Click()
UserForm1.Hide
UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
End Sub作者: 准提部林 時間: 2016-1-17 17:09
Private Sub CommandButton1_Click()
Dim PassWD, xE1 As Range, xE2 As Range, T$
If TextBox1 = "" Then MsgBox "請輸入ID": Exit Sub
If TextBox2 = "" Then MsgBox "請輸入密碼": Exit Sub
Set xE1 = [交接事項!A65536].End(xlUp)(2)
Set xE2 = [交接事項!I65536].End(xlUp)(2)
PassWD = Application.VLookup(TextBox1, [Sheet3!E:F], 2, 0)
If IsError(PassWD) Then T = "ID錯誤"
If T = "" Then If PassWD & "" <> TextBox2.Text Then T = "密碼錯誤"
If T <> "" Then
xE2.Resize(1, 4) = Array(Date, Time, TextBox1, T): MsgBox T: GoTo 999
End If
xE1.Resize(1, 3) = Array(Date, Time, TextBox1): MsgBox "登入成功"
999:
If xE1.Row > 4500 Or xE2.Row > 4500 Then MsgBox "記錄量過大,請清理舊記錄!"
End Sub