能帮助我写个完整的代码吗?
追答Private Sub Worksheet_Change(ByVal Target As Range)
a = Target.Row()
b = Target.Column()
If a 1 Then
If Cells(a, b) = "" And Cells(a - 1, b) "" Then
Rows(a - 1 & ":" & a - 1).Copy
Cells(a, b).Select
ActiveSheet.Paste
c = Cells(a, b)
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = c
Cells(a, b).Select
End If
End If
End Sub
您好!我运行代码发现,连同上一行的数据也复制了,我想只复制公式即可,不用复制没有公式的数据,应该如何修改代码?非常感谢您!
追答用下面的代码吧,我重写过了!
Private Sub Worksheet_Change(ByVal Target As Range)
a = Target.Row()
b = Target.Column()
Application.ScreenUpdating = False
If a 1 Then
If Cells(a, b) = "" And Cells(a - 1, b) "" Then
For x = 1 To 256
If Cells(a - 1, x).HasFormula = True Then
Cells(a - 1, x).Copy
Cells(a, x).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Next x
Cells(a, b).Select
End If
End If
Application.ScreenUpdating = True
End Sub
能给出完整的代码吗