excel中锁定单元格后,怎么才能在任何一个位置插入一行,都能自动复制上一行的公式?

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
我复制别人个VBA程序,执行时老是显示编译错误,缺少end sub,请帮我看下是为什么
Sub aaa()
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

我试了一下第一段代码运行正常,但好像没有实现你说的功能,可能是你弄错了吧,这一段代码应当复制到工作表里的,而不是整个工作薄里。
温馨提示:答案为网友推荐,仅供参考
相似回答