I am trying to make an easy way for people to add new rows to a workbook so that they maintain the conditional formatting and merging from the rows above. I have written the following code in the VBA:
Public Sub AddNewRow()
ActiveCell.EntireRow.Copy ActiveCell.Offset(1)
ActiveCell.PasteSpecial (xlPasteAllMergingConditionalFormats)
End Sub
I get the 1004 error, but the code seems to work, I still get a new row with the functionality and design of the row above. What can I do to make the error go away, or the code error free?
Amanda Doty Nerdy_Knitter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
It is a little vague as to exactly what you’re trying to achieve, but try this alternative which I think might get you what you want:
Public Sub AddNewRow()
With ActiveCell.EntireRow
.Copy
.Offset(1).PasteSpecial xlPasteFormats
End With
End Sub
Note xlPasteFormats
does include merged cells, but does not include the values.