Insert row macro

Sicar

New Member
Joined
Mar 20, 2025
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that I want to use a macro to copy a specific row and insert it where the cursor is when I click the button.

It be be preferable if the macro can insert a single row or a number of rows depending on how many are selected.
 
Welcome to the Board!

Will it always be copying FROM a specific row number (that can be hard-coded into the VBA code)?
Will the rows you are inserting ALWAYS be BELOW the row that you want to copy from?
 
Upvote 0
If the answer to both my question is "Yes", here is code that should do what you want.
I used row 4 as the row to copy from in this example, but you change that number to whatever you need it to be.
VBA Code:
Sub MyRowCopyMacro()
    Rows("4").Copy
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Solution
If the answer to both my question is "Yes", here is code that should do what you want.
I used row 4 as the row to copy from in this example, but you change that number to whatever you need it to be.
VBA Code:
Sub MyRowCopyMacro()
    Rows("4").Copy
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
End Sub
Hi Joe,
Thanks for the prompt response.

Yes the row to be copied will always be the same, row 7 in my case, and it needs to be inserted where the cursor is, this could be anywhere on the sheet eg row 20.

Tried the above code and it works, thank you very much
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0
Hi Joe,
Thanks for the prompt response.

Yes the row to be copied will always be the same, row 7 in my case, and it needs to be inserted where the cursor is, this could be anywhere on the sheet eg row 20.

Tried the above code and it works, thank you very much

You are welcome.
Glad I was able to help!
Do you know if the macro can be amended so that it still runs, but with a cell selected rather than selecting the row below which I want to insert the copied row?
 
Upvote 0
This will do that, but only for one row (where the Active Cell is):
VBA Code:
Sub MyRowCopyMacro()
    Rows("4").Copy
    Rows(ActiveCell.Row).Insert Shift:=xlDown
    Application.CutCopyMode = False
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top