Copy Row of Data from sheet1 to sheet2 with User-form

Aamir, a website visitor, is trying to copy a row of data from sheet1 to sheet2 with a user form. The user-form has a text-box and a command button. On clicking on the command button after entering a number in the text box, the relevant row of data should be copied from Sheet1 to Sheet2 in an Excel workbook.
The complete VBA code or macro for the command button is given below:
Private Sub CommandButton1_Click()
Dim myrow As Integer
myrow = Val(TextBox1.Text)
Rows(myrow).Copy
Sheet2.Activate
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets(“sheet2”).Rows(erow)
Worksheets(“sheet1”).Activate

End Sub

Watch the training video:


View the video on YouTube

8 thoughts on “Copy Row of Data from sheet1 to sheet2 with User-form

  1. sandip

    Hi Dinesh sir I tried with the above mentioned code but getting below error.
    ‘subscript out of range’.
    Why so?please help me on it.

    Reply
  2. Ayaz

    I am trying to do a little bit different with the above code, instead of copying I want to cut and paste the entire row. So I change code to

    Rows(myrow).Cut

    else I use the same but I got a runtime error 9 script out of range. Can you please guide me.

    Thanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *