Excel 与行动态相交

Excel 与行动态相交,excel,vba,Excel,Vba,我尝试将目标范围与某行相交,并动态更改: 我用的是: If Not intersect ([1:7],target) Is Nothing Then 这是可行的,但是: Dim n as Integer : n = 7 If Not intersect ([1:n],target) Is Nothing Then 返回错误424[]不允许使用您需要拼写的变量: Dim n as Integer : n = 7 If Not intersect (Range("1:" & n),tar

我尝试将目标范围与某行相交,并动态更改: 我用的是:

If Not intersect ([1:7],target) Is Nothing Then
这是可行的,但是:

Dim n as Integer : n = 7
If Not intersect ([1:n],target) Is Nothing Then
返回错误424

[]不允许使用您需要拼写的变量:

Dim n as Integer : n = 7
If Not intersect (Range("1:" & n),target) Is Nothing Then  
[]不允许您需要详细说明的变量:

Dim n as Integer : n = 7
If Not intersect (Range("1:" & n),target) Is Nothing Then  
[]语法是以下内容的快捷方式:

[]语法是以下内容的快捷方式:

尝试:

尝试:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim n As Integer: n = 7

    If Not Intersect(Target, Rows("1:" & n)) Is Nothing Then
        MsgBox "in"
    End If

End Sub