I have the following code to insert a new row based on the cell value. How can I modify this to also copy the value in column A for example) to the newly inserted row?
我有以下代码基于单元格值插入新行。如何修改它以将例如A列中的值复制到新插入的行?
Private Sub Worksheet_Change(ByVal Target As Range)
Set Rng = Range("B11:B50")
If Target.Count = 1 Then
If Target.Value = "Annual" Then
If Not Intersect(Target, Rng) Is Nothing Then
Application.EnableEvents = False
Target(1).Offset(1, 0).EntireRow.Insert Shift:=xlDown
Application.EnableEvents = True
End If
End If
End If
End Sub
1 个解决方案
#1
0
Cells(Target.Row + 1, 1).Value = Cells(Target.Row, 1).Value
To copy both A & B
要复制A和B
Cells(Target.Row + 1, 1).Value = Cells(Target.Row, 1).Value
Cells(Target.Row + 1, 2).Value = Cells(Target.Row, 2).Value
#1
0
Cells(Target.Row + 1, 1).Value = Cells(Target.Row, 1).Value
To copy both A & B
要复制A和B
Cells(Target.Row + 1, 1).Value = Cells(Target.Row, 1).Value
Cells(Target.Row + 1, 2).Value = Cells(Target.Row, 2).Value