- 帖子
- 28
- 主題
- 13
- 精華
- 0
- 積分
- 78
- 點名
- 0
- 作業系統
- windows xp
- 軟體版本
- excel 2003
- 閱讀權限
- 20
- 註冊時間
- 2013-12-4
- 最後登錄
- 2023-3-29
|
3#
發表於 2016-1-16 10:09
| 只看該作者
麻煩各位高手幫忙了,紅色部份是小弟想要增加判斷寫入儲存格的地方
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的資料
End If
GoTo 101
Exit For
End If
end if
Next
GoTo 100
100
MsgBox "帳號錯誤"
'GoTo 1100 '為統計登入正確或強制登入記錄,故登入錯誤也列入資料
UserForm1.TextBox2.Value = ""
UserForm1.TextBox1.Value = ""
'Sheets("sheet1").Activate '停留在登入頁面避免跑到帳密頁面
Exit Sub
101
UserForm1.Hide
UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
'Sheets("sheet1").Activate '停留在登入頁面避免跑到帳密頁面
End Sub
Private Sub CommandButton2_Click()
UserForm1.Hide
UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
End Sub |
|