I am very new to VBA and am stumped! I have an Excel worksheet that I need to have users access by entering a Username and Password. I keep the user names and passwords on another tab in the same file. I am trying to verify that the user name and user password match the list before allowing the user to access the spreadsheet. I am getting "method range of object _global failed" error and I cannot seem to locate the error in my code. Would someone please help? Thank you!
Sub Login_Click()
Dim Username As Range
Dim RowNo As Long
Dim ws3 As Worksheet
Dim aCell As Range
On Error GoTo ErrorHandler
If (Range(d4)) = 0 Then
Range(d4).SetFocus
MsgBox "Please select your Username"
Exit Sub
End If
If (Range(d5)) = 0 Then
Range(d5).SetFocus
MsgBox "Password cannot be empty"
Exit Sub
End If
Application.ScreenUpdating = False
Set ws3 = Worksheets("Sheet3")
Username = Range(d4)
Set aCell = ws3.Columns(1).Find(What:=Username, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'~~> If match found
If Not aCell Is Nothing Then
RowNo = aCell.Row
If Range(d5) = aCell.Offset(, 1) Then
FrmMenu.Show
Else
MsgBox "Unable to match User Name or User Password, Please try again", vbOKOnly
End If
Else '<~~ If not found
MsgBox "Unable to match User Name or User Password, Please try again", vbOKOnly
End If
ws3.Visible = xlSheetVeryHidden
CleanExit:
Set ws3 = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Err.Description
Resume CleanExit
End Sub
Bookmarks