在循环中添加 vlookup 的运行时错误 9

Run-time error 9 for adding vlookup in a loop

提问人:PYC 提问时间:10/9/2023 最后编辑:Mayukh BhattacharyaPYC 更新时间:10/9/2023 访问量:45

问:

我使用以下代码将 vlookup 函数添加到循环中的某个单元格。在一点之后,我得到运行时 9 或 1004。我无法自己处理这个问题。提前非常感谢您的支持。

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim V As Range
    Dim cell1 As Range
    Dim isect1 As Range
    Set V = Range("D4:D29")
    Set isect1 = Intersect(Target, V)
    If isect1 Is Nothing Then
        Exit Sub
    Else
        For Each cell1 In isect1
            If cell1.Value <> "" Then
                cell1.Offset(0, 1).Value = WorksheetFunction.VLookup(cell1, Workbooks("KV_ENVANTER.xlsm").Sheets("sheet3").Range("D2:E9"), 2, False)
            ElseIf IsEmpty(cell1.Value) = True Then
                cell1.Offset(0, 1).ClearContents
            End If
        Next cell1
    End If
End Sub
Excel VBA 循环运行 时错误 vlookup

评论

1赞 Notus_Panda 10/9/2023
您在哪一行收到错误?我找不到任何本质上不正确的自动取款机。
1赞 Notus_Panda 10/9/2023
除了您的工作簿或工作表名称有拼写错误之外,我不知道还有什么问题。
1赞 SJR 10/9/2023
当它出错时,真的有匹配吗?
1赞 SJR 10/9/2023
另一个工作簿是否打开?
1赞 PYC 10/9/2023
它给出一个错误,因为文件名已在其他计算机上更改。感谢大家的贡献。你让我更接近解决方案

答: 暂无答案