Hi i am new to Excel and i am doing a spreadsheet system of stock control for a college project but i keep hitting an Run-time Error '1004' Unable to get the VLookup property of the WorksheetFunction Class.
here is the current code for the login button.
if anyone can tell me why it is giving me this error that would be nice and also help me fix it so i can learn from what mistake that i have made if there is any.
It did not give me this error when i take out the false in the VLookup after the IsError line but then it still logs you in to the system. (at current time logging in to the system notice is the cell A2 on the main menu sheet)
here is the current code for the login button.
Code:
Private Sub Login_Click()
Dim Username, Password As String
Username = UsernameT.Text
Password = PasswordT.Text
Sheets("Accounts").Visible = True
Set Users = Sheets("Accounts").Range("A6:B56")
Set Pass = Sheets("Accounts").Range("B6:C56")
Dim Usr As Variant
Dim Pwd As Variant
Usr = Application.WorksheetFunction.VLookup(Username, Users, 2)
Pwd = Application.WorksheetFunction.VLookup(Password, Pass, 2)
If IsError(Usr) = False Then
If Application.WorksheetFunction.VLookup(Username, Users, 2, False) = Password Then
MsgBox "Login Successful.", vbInformation, "Success"
Sheets("Main Menu").Range("a2") = Username
Unload LoginForm
Else
MsgBox "Login Failed.", vbCritical, "Failed"
End If
End If
Sheets("Accounts").Visible = False
Unload LoginForm
End Sub
It did not give me this error when i take out the false in the VLookup after the IsError line but then it still logs you in to the system. (at current time logging in to the system notice is the cell A2 on the main menu sheet)