应用VLOOKUP没有任何价值

我正在input基于VLOOKUP代码的数据,但不断收到错误。

For Each Cell In Rng Cell.Offset(0, 2).Value = Application.WorksheetFunction.VLookup(Cell, Table2, 1, False) Next 

我想要列C发布VLOOKUP值或返回一个消息'返回的项目不扫描'。 我正在使用一个error handling程序来做到这一点,但是当它运行时,我不断收到错误。

  'MyErrorHandler: ' If Err.Number = 1004 Then ' Cell.Offset(0, 2).Value = "Returned Item Not Scanned" ' ElseIf Err.Number = 13 Then ' MsgBox "Incorrect Exceptions Data." ' Else ' ' End If 

错误是指出'无法获取WorksheetFunction类的VLookup属性。

谁能帮忙?

尝试下面的代码段,我使用Application.VLookup来捕获错误。

(在此方法中捕获VLookup错误时,您没有得到1004的Err.Number

 Option Explicit Sub VLookup_with_ErrHandling() Dim Cell As Range Dim Rng As Range Dim Table2 As Range ' modify "Table2" range to your needs Set Table2 = Sheets("Sheet1").Range("A1:C20") ' modify "Rng" range to your needs Set Rng = Sheets("Sheet2").Range("A1:A10") For Each Cell In Rng If Not IsError(Application.VLookup(Cell, Table2, 1, False)) Then Cell.Offset(0, 2).Value = Application.VLookup(Cell, Table2, 1, False) Else Cell.Offset(0, 2).Value = "Returned Item Not Scanned" End If Next End Sub