Insert (paste) multiple rows below a user-selected cell

zankzank

New Member
Joined
Mar 21, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Dear MrExcel community,
I am VBA beginner user and I am struggling with the following problem.
Basically, I need to copy all rows (variable number of rows, hence I am using the LastRow function) from Sheet2 and insert them below a user-selected cell (via InputBox) in Sheet1.

I wrote the following but it basically just adds and empty row.
However, if the destination range is fixed, the same macro would work
frown.gif


Sub Macro1()
Dim LastRow As Long
LastRow = Sheets("Sheet2").Cells(Sheets("Sheet2").Rows.Count, "A").End(xlUp).Row
Dim myReply As Range

Sheets("Sheet2").Range("A2:A" & LastRow).EntireRow.Copy
Set myReply = Application.InputBox(prompt:="Please any Stage cell: resupply stages will be added ABOVE this cell", Type:=8)
myReply.EntireRow.Select

Selection.Insert Shift:=xlDown

End Sub

Any help would be greatly appreciated!
Best,
Silvano
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try it as below:
VBA Code:
Sub Macro1()
    Dim LastRow As Long
    Dim myReply As Range
    
    LastRow = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
    
    Set myReply = Application.InputBox(prompt:="Please select any Stage cell: resupply stages will be added BELOW this cell", Type:=8)
    Sheets("Sheet2").Range("A2:A" & LastRow).EntireRow.Copy
    myReply.EntireRow.Insert Shift:=xlDown
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Solution
You're welcome, thanks for the feedback.

You can mark a solution in the thread by clicking the tick ✔ on the right side of the post that answered your question.
 
Upvote 0
Done! Thank you again for your kind and lightning-fast support: this community is awesome!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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