I am trying to create a Macro in Excel to place a line below whichever cell is highlighted, and then copy formulas only to that line in the correct cells.
So far I have managed to get the new line inserted and populated by copying the entire row contents.
What I need to know is how to I get the Macro to clear the data from specific cells, so I can leave the cells with formulas in intact?
I've tried the Selection.ClearContents
command, but this just clears the entire rows data, including formulas.
Here is my code so far
Sub Button500_Click()
Dim lRow As Long
Dim lRsp As Long
'On Error Resume Next
lRow = Selection.Row()
'lRsp = MsgBox("Insert New row below " & lRow & "?", _
' vbQuestion + vbYesNo)
'If lRsp <> vbYes Then Exit Sub
Rows(lRow).Select
Selection.Copy
Rows(lRow + 1).Select
Selection.Insert Shift:=xlUp
'Paste formulas and conditional formatting in new row created
Rows(lRow).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone
Selection.ClearContents
Application.CutCopyMode = False
End Sub