Reputation: 9
I've created a macro in Excel to copy a row in one of my sheets and insert the row into another sheet above the user's selected row. The macro is as follows and works correctly:
Sub addTestProductRow()
Sheets("Macro templates").Range("B2:J2").Copy
Selection.Insert Shift:=xlDown
End Sub
However, I wish to add to this macro to make it only insert in the columns B to J, regardless of which cell the user has selected. I still wish for it to insert above the users selected row, just in the specified column range.
Upvotes: 0
Views: 1156
Reputation: 152660
This should do what you want:
Sub addTestProductRow()
Dim t As Long
t = Selection.Row
Rows(t).Insert
Sheets("Macro templates").Range("B2:J2").Copy
Range("B" & t).PasteSpecial
End Sub
Upvotes: 0