VBA INDEX MATCH 运行-时间错误“1004”:应用程序定义或对象定义的错误

VBA INDEX MATCH Run-time error '1004': Application-defined or object-defined error

我收到一个 运行 时间错误:“当我 运行 以下代码

时出现应用程序定义或对象定义的错误
    For i = 4 To lastOutputCol
        If (Sheets("Mort Rates").Cells(1, i).Value Mod 5) = 0 Then
            For x = 2 To numOutputRows

                With Sheets("Mort Rates")
                .Cells(x, i) = Application.WorksheetFunction.Index(Sheets("Input").Range(Sheets("Input").Cells(17, dbPerkCol), _
                Sheets("Input").Cells(lastInputRow, dbPerkCol + 2)), Application.WorksheetFunction.Match(.Cells(x, 2) & .Cells(1, i) & .Cells(x, 3), _
                Sheets("Input").Range(Sheets("Input").Cells(17, 1), Sheets("Input").Cells(lastInputRow, 1)), 0), 1)
                End With

            Next x
        End If
    Next i

问题出在行

.Cells(x, i) = Application.WorksheetFunction.Index(Sheets("Input").Range(Sheets("Input").Cells(17, dbPerkCol), _
Sheets("Input").Cells(lastInputRow, dbPerkCol + 2)), Application.WorksheetFunction.Match(.Cells(x, 2) & .Cells(1, i) & .Cells(x, 3), _
Sheets("Input").Range(Sheets("Input").Cells(17, 1), Sheets("Input").Cells(lastInputRow, 1)), 0), 1)

我已经检查过,所有使用的变量都是正确的。

编辑:

我正在尝试从输入 sheet 表和 return 正确值进行索引匹配。 我现在正在使用此代码:

    For i = 4 To lastOutputCol
        If (Sheets("Mort Rates").Cells(1, i).Value Mod 5) = 0 Then
            For x = 2 To numOutputRows

                With Sheets("Mort Rates")
                .Cells(x, i).Value = Application.WorksheetFunction.Index(Sheets("Input").Range(Sheets("Input").Cells(17, dbPerkCol), _
                Sheets("Input").Cells(lastInputRow, dbPerkCol + 2)), Application.WorksheetFunction.Match(.Cells(x, 2) & .Cells(1, i) & .Cells(x, 3), _
                Sheets("Input").Range(Sheets("Input").Cells(17, 1), Sheets("Input").Cells(lastInputRow, 1)), 0), 1)
                End With

            Next x
        End If
    Next i

代码工作了一段时间(填充了我想要的大约一半的单元格)然后我得到了这个错误: "Unable to get the Mtch property of the WorksheetFunction class"

Dim ws as Worksheet
set ws = ThisWorkbook.Worksheets("Input")
For i = 4 To lastOutputCol
    If (Sheets("Mort Rates").Cells(1, i).Value Mod 5) = 0 Then
        For x = 2 To numOutputRows

            With ThisWorkbook.Sheets("Mort Rates")
                .Cells(x, i).Value = Application.Index(ws.Range(ws.Cells(17, dbPerkCol), _
                ws.Cells(lastInputRow, dbPerkCol + 2)), Application.Match(.Cells(x, 2) & .Cells(1, i) & .Cells(x, 3), _
                ws.Range(ws.Cells(17, 1), ws.Cells(lastInputRow, 1)), 0), 1)
            End With

        Next x
    End If
Next i