2
我正试图在vba上创建一个登录用户窗体,但它会返回标题中所述的错误。所以这里有一些背景。运行时错误:无法获取WorksheetFunction类的Vlookup属性
我有一张名为“User_List”的工作表,其中有用户名和他们的密码。范围从范围B3开始到C1000。列B具有所有用户名,而列C具有密码。我想创建一个登录用户表单,以便在用户输入用户名和密码后,vba将搜索用户列表并确定详细信息是否正确。一旦确认,vba将引导用户访问另一个称为主页的表格。以下是我的代码。
Private Sub MLIB_Click()
Dim UserName As String
Dim PassWord As String
' MUN is the name of the textbox associated to the Username
' MPW is the name of the textbox associated to the Password
UserName = MUN.Value
PassWord = MPW.Value
If UserName = Application.WorksheetFunction.VLookup(UserName, Sheets("User_List").Range("B3:C1000"), 1, True) Then
If PassWord = Application.WorksheetFunction.VLookup(PassWord, Sheets("User_List").Range("B3:C1000"), 2, True) Then
Sheets("Home_Page").Activate
Unload Me
End If
End If
MsgBox "Sorry, Incorrect Login Details"
End Sub
一直试图弄清楚这一点,但它需要很长时间!感谢任何帮助!
它给了我一个错误 - 运行时错误'438'(对象不支持这个属性或方法),它突出显示了下面的代码。 If Not IsError(Application.Match(UserName,.Column(2),0))Then – Stu
我的歉意。这应该是'.Columns(2)',而不是'.Column(2)'。 – Jeeped
它完美的作品!谢谢!! – Stu