我正在尝试根据员工ID在用户表单中使用VLOOKUP
公式提取员工姓名。
以下代码正在运行。
Private Sub CommandButton2_Click()
Label4.Caption = Sheet1.Application.WorksheetFunction.VLookup(TextBox1.Text, Range("A:B"), 2, False)
End Sub
答案 0 :(得分:-1)
这里的问题是找不到匹配项。这是错误消息的原因。这里是 你应该使用的VBA代码:
Private Sub CommandButton2_Click()
On Error Resume Next
Label1.Caption = Sheet1.Application.WorksheetFunction.VLookup(TextBox1.Text, Range("A:B"), 2, False)
If Err.Number <> 0 Then
Err.Clear
Label1.Caption = "not found"
End If
End Sub