无法获取WorksheetFunction类错误的VLookup属性的工作表

在这里输入图像说明

Private Sub TextBox2_AfterUpdate() 'Badge Number On Error GoTo Err Dim tbl As ListObject, fndStr As String Set tbl = Sheet9.ListObjects("EmployeeList") fndStr = Trim(Me.TextBox2.Value) MsgBox fndStr If fndStr <> "" Then Me.TextBox3.Value = Application.WorksheetFunction.VLookup(fndStr, tbl, 2, False) '<-- Error Line End If Exit Sub Err: MsgBox Err.Description End Sub 

我有一个名为“EmployeeList”的表,我正在使用徽章号码进行简单的查找,但我得到了不明原因的错误。 我知道之前也有类似的问题,但是在发布之前我已经阅读过。

您可以清楚地看到图像中的表名,input值为10 ,表示vlookup函数的第一个参数,但是它不会返回任何值,但会给出错误。 不知道什么是错的。

  'I tried this as well Me.TextBox3.Value = Application.WorksheetFunction.VLookup(fndStr, Sheet9.Range("A1:F" & Rows.Count), 2, False) '<-- Error Line 'And this Me.TextBox3.Value = Application.WorksheetFunction.VLookup(fndStr, Sheet9.Range("EmployeeList"), 2, False) '<-- Error Line 

也不知道原因,我做不到

  Application.Vlookup as well Like when I do Application.V Vlookup doesn't shows up in the list. 

有两个问题。

第一,你试图解决的是,你需要在Vlookup中的Range作为Arg2 。 由于你的tbl是一个ListObject 。 你可以简单地使用tbl.Range ,参见ListObject.Range属性 。

第二个是, Vlookup不会在一列数字中findstring。 而你的第一列是一列数字。 所以你需要将string转换为数字。

 Me.TextBox3.Value = Application.WorksheetFunction.VLookup(CDbl(fndStr), tbl.Range, 2, False) 

应该pipe用。

请find下面的代码,我已经使用评估方法来获得vlookup结果。

 Private Sub TextBox2_AfterUpdate() Dim fndStr As String On Error GoTo Err_Desc fndStr = Trim(Me.TextBox2.Value) MsgBox fndStr If fndStr <> "" Then '// Using Eval method Me.TextBox3.Value = Evaluate("=VLOOKUP(" & fndStr & ",EmployeeList[#All],2,0)") End If Exit Sub Err_Desc: MsgBox Err.Description End Sub