我知道这是一个简单的问题,但我很难与此,我有2个文本框(txtUs,txtPass)和一个命令/注销按钮,验证数据并让他们输入用户名和密码。如果他们输入了错误的密码或用户名,现在会出现 错误信息。但是如果他们得到了两个正确的信息,它会显示一条消息“您已成功注销”。问题在于,如果在它之前有空白行,程序将无法找到数据。它只识别数据,如果数据'没有空列,然后从列A2开始。任何帮助/更正将不胜感激。当数据已经存在时延误一条错误信息
Dim user_name As String
Dim user_pass As String
If Not IsNull(UserForm4.txtUs) Then
user_name = UserForm4.txtUs
Else
MsgBox "Username or password is Incorrect"
Exit Sub
End If
If Not IsNull(UserForm4.txtPuss) Then
user_pass = UserForm4.txtPuss
Else
MsgBox "Username or password is Incorrect"
Exit Sub
End If
Dim counter As Integer
counter = 2
Do Until ThisWorkbook.Sheets("Sheet2").Cells(counter, 1).Value = ""
If ThisWorkbook.Sheets("Sheet2").Cells(counter, 1).Value = user_name And ThisWorkbook.Sheets("Sheet2").Cells(counter, 2).Value = user_pass Then
MsgBox ("You have been logged-out")
UserForm5.txt_Mon_in.Text = Format(ThisWorkbook.Sheets("Sheet2").Cells(counter, 4).Value, "hh:mm AMPM")
UserForm5.txt_Mon_out.Text = Format(Time, "hh:mm AMPM")
UserForm5.Label1 = Sheets("employees").Cells(counter, 2).Value & Sheets("employees").Cells(counter, 3).Value & Sheets("employees").Cells(counter, 4).Value
UserForm5.Label2 = Date + 14
UserForm5.txt_Mon_Rate.Text = Sheets("employees").Cells(counter, 6).Value
UserForm5.Show
ThisWorkbook.Sheets("Sheet2").Cells(counter, 5).Value = Time
UserForm4.Hide
Set UserForm4 = Nothing
Exit Sub
End If
counter = counter + 1
Loop
MsgBox ("Username or password is incorrect")
添加变量来计算连续的空格数(复位到0时你打到一个非空白的单元格),并在计数大于某个阈值时退出循环 - 例如。在连续10次空白后退出。 –
@tim威廉姆斯..我会尝试..感谢这个想法。 – user2123999