VBA excel 相交时复制上面的单元格

VBA excel copy above cells when intersect

我需要 Excel 将特定范围复制到当前 selected 的行。

例如我有这样的数据:

当我select A3时,我需要Excel自动复制范围C2:F2到C3:F3,像这样

等等...如果我selectA4,我需要复制C3:F3到C4:F4...

请问这怎么可能?

我觉得这更像是自动填充。您应该从 C2:F2.

开始填写

Range.AutoFill

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Target.Row = 1 And Not Intersect(Target, Range("A2", Columns("A"))) Is Nothing Then
        With Target.Offset(-1).EntireRow.Range("C1:F1")
            .AutoFill Destination:=.Resize(2), Type:=xlFillDefault
        End With
    End If
End Sub

Range.Copy

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Target.Row = 1 And Not Intersect(Target, Range("A2", Columns("A"))) Is Nothing Then
        With Target.EntireRow.Range("C1:F1")
            .Offset(-1).Copy Destination:=.Cells
        End With
    End If
End Sub