我正在使用以下代码在单击中插入单元格下的一行,并从上方复制格式和公式。但是,我希望它仅复制公式和格式,从列a:k复制。
我已经尝试了几个不同的事情,但是不断出现错误。我敢肯定,对于那里的人来说,这是一个简单的修复,我只是要转弯,我应该如何调整代码? - 请帮助
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
End Sub
这可以做您想要的吗?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row = 1 Then Exit Sub
Cancel = True
Application.ScreenUpdating = False
With Target.Worksheet
.Rows(Target.Row + 1).Insert (xlDown)
.Rows(Target.Row + 1).Clear
.Range("A" & Target.Row & ":K" & Target.Row).Copy
With .Range("A" & Target.Row + 1 & ":K" & Target.Row + 1)
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteFormulas
' Remove this code here if you DON'T want to clear the cells
' that do not have formulas.
On Error Resume Next
.SpecialCells(xlCellTypeConstants).ClearContents
On Error GoTo 0
End With
End With
Application.CutCopyMode = False
Target.Activate
Application.ScreenUpdating = True
End Sub
...如果是这样,请添加错误检查和任何其他要求,并希望可以去。