TPortsmouth
New Member
- Joined
- Apr 6, 2017
- Messages
- 41
Hello,
With the help of Excel expert here, I've created below VBA to copy a user defined range and paste at the bottom.
However, I don't know how to change the code into the next row underneath the copied data.
For example, after execute the Macro, Range(4:6) will be copy.
And then using "Insert copied Cells" to insert the whole 3 row's data into the underneath row.
Apart from that, how do I change the code from a specific range to the whole row?
I've tried to changed to something like below and it return error
Please offer help, thank you.
With the help of Excel expert here, I've created below VBA to copy a user defined range and paste at the bottom.
Code:
Sub CopyRecord()
'
lr = Range("A" & Rows.Count).End(xlUp).Row + 1
'lr is to determine the Last Row
Last = Range("A" & Rows.Count).End(xlUp).Row
'This is to to determine the last Row address
Record_Number = Application.InputBox("Which record you want to copy?", Type:=1)
If Record_Number = "" Or Record_Number = 0 Then MsgBox ("Cancelled by user"): Exit Sub
' this checks for Cancel or 0
If Record_Number > Last Then MsgBox "Record does not exist!": Exit Sub
' This is to display error message if user entered a number larger than the existing record number.
Range("A" & Record_Number & ":E" & Record_Number + 2).Copy
Range("A" & lr).Select
ActiveSheet.Paste
End Sub
However, I don't know how to change the code into the next row underneath the copied data.
For example, after execute the Macro, Range(4:6) will be copy.
And then using "Insert copied Cells" to insert the whole 3 row's data into the underneath row.
Apart from that, how do I change the code from a specific range to the whole row?
Code:
Range("A" & Record_Number & ":E" & Record_Number + 2).Copy
I've tried to changed to something like below and it return error
Code:
Range(Record_Number : Record_Number + 2).Copy
Please offer help, thank you.