Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 运行时错误';1004';:方法';相交';对象的'_全球';失败_Vba_Excel_Runtime Error - Fatal编程技术网

Vba 运行时错误';1004';:方法';相交';对象的'_全球';失败

Vba 运行时错误';1004';:方法';相交';对象的'_全球';失败,vba,excel,runtime-error,Vba,Excel,Runtime Error,我对这一点还相当陌生,一直在努力寻找答案。也许它的定义不正确或根本不正确。也许它没有指向正确的工作表。我不是很确定。。。任何帮助都将不胜感激!谢谢 获取此行的错误信息: 设置Inte=Intersect(A,目标)如果您用以下命令更改问题行,它是否有效: if not intersect(A, Target) is nothing then Set Inte = Intersect(A, Target) 如果您用以下方法更改问题行,是否有效: if not intersect(A, Targ

我对这一点还相当陌生,一直在努力寻找答案。也许它的定义不正确或根本不正确。也许它没有指向正确的工作表。我不是很确定。。。任何帮助都将不胜感激!谢谢

获取此行的错误信息:


设置Inte=Intersect(A,目标)
如果您用以下命令更改问题行,它是否有效:

if not intersect(A, Target) is nothing then Set Inte = Intersect(A, Target)

如果您用以下方法更改问题行,是否有效:

if not intersect(A, Target) is nothing then Set Inte = Intersect(A, Target)
您的代码中存在“魔鬼接触”,因为如果用户在您将此事件处理程序放置在其模块中的工作表的“J”列中键入“Closed”,它将删除
目标
行(
target.EntireRow.Delete
),从而使
target
不被引用,并为以后使用
target
时抛出错误做好准备,该错误恰好位于
Set Inte=Intersect(A,target)

但是,如果我正确地阅读了您的代码,这甚至不应该发生,因为后一行只针对跨列“C”,如果它在列“J”中,则不能

如果上述内容正确,您可能需要使用如下代码

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim nxtRow As Long
Dim Inte As Range, r As Range

Application.EnableEvents = False

With Target
    'Determine Target Colunm
    If .Column = 10 Then

        'Check for "Closed", Copy/Delete Row if found
        If .Value = "Closed" Then
            nxtRow = Sheets("Closed Locks").Range("J" & Rows.Count).End(xlUp).Row + 1
            .EntireRow.Copy _
            Destination:=Sheets("Closed Locks").Range("A" & nxtRow)
            .EntireRow.Delete

        ElseIf Target = "TD" Then
            'Check for "TD", Copy/Delete Row if found
            nxtRow = Sheets("TD Locks").Range("J" & Rows.Count).End(xlUp).Row + 1
            .EntireRow.Copy _
            Destination:=Sheets("TD Locks").Range("A" & nxtRow)
            .EntireRow.Delete
        End If

    Else

        'Adds date when borrower name is entered
        Set Inte = Intersect(.Cells, .Parent.Range("C:C"))
        If Not Inte Is Nothing Then
            For Each r In Inte
                If r.Offset(0, 8).Value = "" Then r.Offset(0, 8).Value = Date
            Next r
        End If

    End If
End With

Application.EnableEvents = True

End Sub
您的代码中存在“魔鬼接触”,因为如果用户在您将此事件处理程序放置在其模块中的工作表的“J”列中键入“Closed”,它将删除
目标
行(
target.EntireRow.Delete
),从而使
target
不被引用,并为以后使用
target
时抛出错误做好准备,该错误恰好位于
Set Inte=Intersect(A,target)

但是,如果我正确地阅读了您的代码,这甚至不应该发生,因为后一行只针对跨列“C”,如果它在列“J”中,则不能

如果上述内容正确,您可能需要使用如下代码

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim nxtRow As Long
Dim Inte As Range, r As Range

Application.EnableEvents = False

With Target
    'Determine Target Colunm
    If .Column = 10 Then

        'Check for "Closed", Copy/Delete Row if found
        If .Value = "Closed" Then
            nxtRow = Sheets("Closed Locks").Range("J" & Rows.Count).End(xlUp).Row + 1
            .EntireRow.Copy _
            Destination:=Sheets("Closed Locks").Range("A" & nxtRow)
            .EntireRow.Delete

        ElseIf Target = "TD" Then
            'Check for "TD", Copy/Delete Row if found
            nxtRow = Sheets("TD Locks").Range("J" & Rows.Count).End(xlUp).Row + 1
            .EntireRow.Copy _
            Destination:=Sheets("TD Locks").Range("A" & nxtRow)
            .EntireRow.Delete
        End If

    Else

        'Adds date when borrower name is entered
        Set Inte = Intersect(.Cells, .Parent.Range("C:C"))
        If Not Inte Is Nothing Then
            For Each r In Inte
                If r.Offset(0, 8).Value = "" Then r.Offset(0, 8).Value = Date
            Next r
        End If

    End If
End With

Application.EnableEvents = True

End Sub

尝试使用
Application.Intersect
尝试使用
Application.Intersect