I still don't fully understand what exactly you want to get, so you have two macros. The first, 99 times you will be asked for your username and password. The second macro will only ask for the password for the user tested in the loop. If you press Cancel at any of the questions, the macro will exit.
Sub Test1()
Dim WsUserName As Worksheet
Dim RgUserPas As Range
Dim c As Range
Dim i As Long
Dim strUserID As String
Dim strPass As String
Dim Level 'As ???
Set WsUserName = Sheets("Table Users")
Set RgUserPas = WsUserName.Range("A2:A100")
For i = 2 To 100
OnceAgain:
strUserID = InputBox("Enter your username:")
If StrPtr(strUserID) Then
If Len(Trim(strUserID)) = 0 Then
GoTo OnceAgain
End If
Set c = RgUserPas.Find(strUserID, LookIn:=xlValues, MatchCase:=False)
If c Is Nothing Then
MsgBox "No user!", vbExclamation, "User Login"
Else
strPass = InputBox("Enter the password for the user " & c.Value & ":")
If StrPtr(strPass) Then
If strPass = c.Offset(, 1).Value Then
Level = c.Offset(, 2).Value
MsgBox "Login Success" & String(2, vbLf) & _
"User:" & vbTab & c.Value & vbLf & _
"Pass:" & vbTab & "OK" & vbLf & _
"Level:" & vbTab & Level, vbInformation, "User Login"
Else
MsgBox "User Password is Wrong", vbCritical, "User Login"
End If 'strPass = c.Offset(, 1).Value
Else
'Cancel was pressed
Exit Sub
End If 'StrPtr(strPass)
End If 'c Is Nothing
Else
'Cancel was pressed
Exit Sub
End If 'StrPtr(strUserID)
Next i
End Sub
Sub Test2()
Dim WsUserName As Worksheet
Dim RgUserPas As Range
Dim c As Range
Dim i As Long
Dim strUserID As String
Dim strPass As String
Dim Level 'As ???
Set WsUserName = Sheets("Table Users")
Set RgUserPas = WsUserName.Range("A2:A100")
For Each c In RgUserPas.Cells
If Len(Trim(c.Value)) > 0 Then
strUserID = c.Value
strPass = InputBox("Enter the password for the user " & strUserID & ":")
If StrPtr(strPass) Then
If strPass = c.Offset(, 1).Value Then
Level = c.Offset(, 2).Value
MsgBox "Login Success" & String(2, vbLf) & _
"User:" & vbTab & c.Value & vbLf & _
"Pass:" & vbTab & "OK" & vbLf & _
"Level:" & vbTab & Level, vbInformation, "User Login"
Else
MsgBox "User Password is Wrong", vbCritical, "User Login"
End If 'strPass = c.Offset(, 1).Value
Else
'Cancel was pressed
Exit Sub
End If 'StrPtr(strPass)
End If 'Len(Trim(c.Value)) > 0
Next c
End Sub
Artik
Bookmarks