[英]Excel VBA - Userform vlookup error handling
我有一個帶有組合框的用戶窗體,該組合框填充了我的設置表中的產品名稱,並且一旦用戶從組合框中選擇了產品,我就會嘗試顯示帶有產品描述的標簽。
除非用戶選擇了沒有產品說明的產品,否則此效果很好,因此vlookup將返回空並導致用戶表單錯誤。
我嘗試了幾種If Error-if為空-Description為0-Description為空的語句,但是似乎沒有任何作用,包括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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.