Application.Match()始终从VBA fx,BUT

时间:2019-05-03 19:27:36

标签: excel vba worksheet-function

当我从即时窗口调用Application.Match()时,它可以工作。从VBA中的模块,它返回“ 91 Obj Var或未设置块”错误。

我尝试从工作表中进行匹配,效果很好。我尝试将“数组” arg更改为“类别”(命名范围,工作簿范围),“ errCodes!B25:B295”,范围(“ category”),范围(“ errCodes!B25:B295”))...我查看了其他错误91,它们与匹配无关。

Function findCD(prevRng As Range)
    Dim oldCDrng As Range
    Dim i As Integer
    Dim nextCD As Integer

    Dim oldC, oldD, newC, newD, oldCD, newCD As String
    On Error GoTo err_hand
    'Argument is always above cell

    '1 find prev cell value
    oldCD = WorksheetFunction.Index(prevRng, 0)
    oldC = Mid(oldCD, 1, 1)
    oldD = Mid(oldCD, 2, 1)

    '2 find next C & D where different
    'find current CD
    oldCDrng = Application.Match("02", Range("category"), 0)

    'next CD is at least CD + 1
    'verify this
    nextCD = oldCD + 1

    nextCDrng = Application.Match(nextCD, Range("errorCodes!D22:D295"), 0)

    '3 return this value

    Exit Function
err_hand:

    findCD = "ERROR!" & Err.Number & " (" & Err.Description & ")"    
End Function

0 个答案:

没有答案