Macro is copy row and paste row based on user input

webbooo

New Member
Joined
Nov 8, 2011
Messages
19
Hello,

I currently have a macro that I recorded that basically copies row 15 and the inserts the copied row to row 18.
While this works ok, over time the number of rows will increase as such that row 15 will be a row that shouldnt be copied.
I'd like to like to look at having a macro that prompts the user which row number should be copied and then prompts for which row number it should be inserted into.

Any help would be appreciated.

Thanks
Adam
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
VBA Code:
Sub v()
Dim c, d
c = Application.InputBox("Enter the row number to be copied.", Type:=1)
If TypeName(c) = "Boolean" Then Exit Sub
d = Application.InputBox("Enter the row number where to insert.", Type:=1)
If TypeName(c) = "Boolean" Then Exit Sub
Rows(Val(c)).Copy
Rows(Val(d)).Insert
Application.CutCopyMode = False
End Sub
 
Upvote 0
Solution
Personally a quicker option.

Assign this to a shortcut (ctrl+shift+v perhaps), copy the row, select the location and use the shortcut

VBA Code:
Sub v()

Rows(ActiveCell.Row).Insert

End Sub
 
Upvote 0
Personally a quicker option.

Assign this to a shortcut (ctrl+shift+v perhaps), copy the row, select the location and use the shortcut

VBA Code:
Sub v()

Rows(ActiveCell.Row).Insert

End Sub
The copy/paste might be part of a larger macro.
Otherwise, it's just as easy to do a manual copy/paste.
 
Upvote 0
VBA Code:
Sub v()
Dim c, d
c = Application.InputBox("Enter the row number to be copied.", Type:=1)
If TypeName(c) = "Boolean" Then Exit Sub
d = Application.InputBox("Enter the row number where to insert.", Type:=1)
If TypeName(c) = "Boolean" Then Exit Sub
Rows(Val(c)).Copy
Rows(Val(d)).Insert
Application.CutCopyMode = False
End Sub
I'd like to simplify as much as possible as the users of the spreadsheet are not experienced with excel. If they can simply enter the row number to copy and then enter the row number to paste/insert it will make things easy. Doing it manually will create confusion as the use of the spreadsheet and number of rows grows.
 
Upvote 0
Does the suggested macro do what you want?
 
Upvote 0
VBA Code:
Sub v()
Dim c, d
c = Application.InputBox("Enter the row number to be copied.", Type:=1)
If TypeName(c) = "Boolean" Then Exit Sub
d = Application.InputBox("Enter the row number where to insert.", Type:=1)
If TypeName(c) = "Boolean" Then Exit Sub
Rows(Val(c)).Copy
Rows(Val(d)).Insert
Application.CutCopyMode = False
End Sub
Does the suggested macro do what you want?

Does the suggested macro do what you want?
How would one modify this code to insert the copied row into a row in another sheet?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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