TPortsmouth
New Member
- Joined
- Apr 6, 2017
- Messages
- 41
Hello Excel VBA expert,
By the help of MrExcel expert's help, I've developed below VBA to copy a specific record to the last row within the same worksheet.
The general idea is when use click the Macro button, a message box appear and copy the 2 row data and paste and the bottom of the same data set.
This is working fine. However, I want to add a validation to Stop the Macro if user enter a record number which does not exist.
However, there is some problem of this statement, and it didn't work. Can you help me on pointing out which part caused the failure?
Thanks.
By the help of MrExcel expert's help, I've developed below VBA to copy a specific record to the last row within the same worksheet.
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 = InputBox("Which record you want to copy?")
If Record_Number < Last Then MsgBox "Record do 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 + 1).Copy
Range("A" & lr).Select
ActiveSheet.Paste
End Sub
The general idea is when use click the Macro button, a message box appear and copy the 2 row data and paste and the bottom of the same data set.
This is working fine. However, I want to add a validation to Stop the Macro if user enter a record number which does not exist.
Code:
If Record_Number < Last Then MsgBox "Record do not exist!": Exit Sub
However, there is some problem of this statement, and it didn't work. Can you help me on pointing out which part caused the failure?
Thanks.