How to error handle 1004 Error with WorksheetFunction.VLookup?

前端 未结 3 457
不思量自难忘°
不思量自难忘° 2020-11-22 06:24

I have this code:

Dim wsFunc As WorksheetFunction: Set wsFunc = Application.WorksheetFunction
Dim ws As Worksheet: Set ws = Sheets(\"2012\")
Dim rngLook As R         


        
3条回答
  •  渐次进展
    2020-11-22 06:52

    From my limited experience, this happens for two main reasons:

    1. The lookup_value (arg1) is not present in the table_array (arg2)

    The simple solution here is to use an error handler ending with Resume Next

    1. The formats of arg1 and arg2 are not interpreted correctly

    If your lookup_value is a variable you can enclose it with TRIM()

    cellNum = wsFunc.VLookup(TRIM(currName), rngLook, 13, False)

提交回复
热议问题