Excel VBA – Userform vlookuperror handling

我有一个用我的设置工作表填充产品名称的combobox,我试图显示一个标签与产品说明一旦用户从combobox中select一个产品。

这很好,除非用户select没有产品说明的产品,因此,vlookup将返回空,并导致用户表单错误。

我尝试了几个如果错误 – 如果是空的 – 说明是0 – 说明是空的语句,但似乎没有工作,包括OnError GoTo Errorhandler。 我在这里做错了什么?

Private Sub Problem_List_Change() Description = Application.WorksheetFunction.VLookup(Problem_List.Text, Worksheets("Settings").Range("l3:o1000"), 4, False) If IsError(Description) Then Desc.Caption = "" Else Desc.Caption = Description End If End Sub 

谢谢,A2K

这对我有用。

 Sub x() Dim r As Variant On Error Resume Next r = Application.WorksheetFunction.VLookup(5, Range("a1:b4"), 2, False) If Not IsEmpty(r) Then Debug.Print "Found" Else Debug.Print "Not Found" End If End Sub