"runtime error 1004"

Sanderch

New Member
Joined
Mar 5, 2010
Messages
27
Please help, im getting a "runtime error 1004" (application defined or object defined error) on the below code (highlighted red) im not good with vba. (can i attached the file?)

I am running a userform with a combobox (UserList) and a text box (PasswordInput) on selecting the button (Logon) i get the below error.

I have two user defined lists named User_List
Code:
=OFFSET(Username_Password!$A$1,1,0,COUNTA(Username_Password!$A:$A)-1,2)
and Users
Code:
 =OFFSET(Username_Password!$A$1,1,0,COUNTA(Username_Password!$A:$A)-1,1)

Sheet name is Username_Password,

Code:
Private Sub Logon_Click()
Dim Password As String
Password = PasswordInput.Text
 
[COLOR=seagreen]'Check to see if data is entered into the UserName combo box[/COLOR]
 
If IsNull(Me.UserList) Or Me.UserList = "" Then
MsgBox "You must select a User Name.", vbOKOnly, "Required Data"
Me.UserList.SetFocus
Exit Sub
End If
 
[COLOR=seagreen]' Looks up password[/COLOR]
[COLOR=#2e8b57][/COLOR] 
[COLOR=red]If Password = WorksheetFunction.VLookup(UserList.Value, Range("Users_List"), 2, 0) Then
[/COLOR]MsgBox "Password Accepted"
Unload Me
Else
MsgBox "Password Incorrect.", vbOKOnly, "Required Data"
Me.PasswordInput.SetFocus
End If
Exit Sub
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try Dim Password as Variant and

Code:
If Password = Application.VLookup(UserList.Value, Range("Users_List"), 2, 0) Then
 
Upvote 0
Hi Vog thants for your post its now saying its

"Runtime error 1004" Method 'range' of object '_global' failed
 
Upvote 0
A good opportunity to point out that using the Option Explicit directive at the top of your code would have highlighted this problem before you'd have got as far as running the code. The compiler would have told you that you were trying to use a non-existent object and refused to go any further.

I always recommend that people use Option Explicit as a matter of course, not only to pick up spelling mistakes but also to make them think carefully about how they use the various data types available to them.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top