Copy Paste Data from one Excel Worksheet to Another Using VBA

How to copy and paste data from one Excel Worksheet to Another Using VBA

I want to search the whole spreadsheet for the product ‘Car’ and paste the whole row (not just the cell). So in this instance it would be row a2, a5, a8 and a10 from sheet 1 to sheet2.
If I have to use macros to automate the whole process what would be the vba code?

Sub mycar()
‘Let’s start at row 2. Row 1 has headers
x = 2
‘Start the loop
Do While Cells(x, 1) <> “”
‘Look for data with ‘Car’
If Cells(x, 1) = “Car” Then
‘copy the row if it contains ‘Car’
‘Go to sheet2. Activate it. We want the data here
‘Find the first empty row in sheet2
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
‘Paste the data here
ActiveSheet.Paste Destination:=Worksheets(“Sheet2”).Rows(erow)
End If
‘go to sheet1 again and actvate it
‘Loop through the other rows with data
x = x + 1
End Sub

Watch the Microsoft Excel training video below to see how you can use the macro (vba code) to copy and paste specific data from Sheet 1 to Sheet 2:

15 thoughts on “Copy Paste Data from one Excel Worksheet to Another Using VBA

  1. alexandru

    I want to copy a file from a page,in a page from another file
    ex, file A sheet1 in file B sheet1
    If you can help

    1. Jessie

      You’re absolutely right. It is a waste of your time and energy to hunt up after someone when thr;1#82&7yee not even polite to you. It’s amazing how some people will be in a serious relationship with someone as discourteous and rude like that. But I sometimes give the impression that I am snobby. I’m shy and usually can’t think of much to say in the first couple of encounters. Takes me a while to warm up. I wonder if that’s why I have so many extroverted friends …

  2. Jan

    hi, i’m loving your page.
    in addition to this, same case but instead i have 2 or more worksheets and i need to copy all rows containing “cars” (following this example) from these sheets to one master file and how can i run this via hit of a button and will refresh data every hit. thanks a lot

  3. Amalendu

    Dear Sir,
    I followed the above mentioned code to copy certain number of row which do I want to paste another work sheet. I have written the following code but it is not working. Can you please guide me where is wrong coding.

    Sub Car()
    Dim X
    X = 2
    Do While Cells(X, 2) “”
    If Cells(X, 2) = “Hero” Then
    erow = Sheet3.Cells(Row.Count, 1).End(xlUp).Offset(1, 0).Row
    ActiveSheet.Paste Destination:=Worksheets(“Sheet3”).Row(erow)
    End If
    X = X + 1
    End Sub

    1. Amalendu

      Just replace 6th last statement and write

      Activesheet.Past Destination:=Worksheet(“Sheet3”).Row(erow,1)

      Now it will work

      Thanks Dinesh Sir for giving us an opportunity to learn VBA .

      1. Krishna Mjk

        Hi Amalendu

        I applied the solution mentioned by you
        but it is not working

        My excel version is 2013

        1. Amalendu

          Hi, Can u sent the coding so that i can help you out, but in my office excel version 2013 it’s working. can u share the codding then only I can suggest you, where it is wrong.


  4. Zoe

    Hi Dinesh

    I am using the code below to copy and paste data from multiple worksheets into a master file
    It works just fine except it only copies over the values of the cells rather than all the formats i.e. cell pattern/colour, can you help?

    Sub OpenFiles()
    Dim MyFolder As String
    Dim MyFile As String
    Dim erow

    MyFolder = “C:\Users\Zoe\Desktop\ZAFiles2 – Working Copies1 – VJC”
    MyFile = Dir(MyFolder & “\*.xlsx”)

    Do While MyFile “”

    Workbooks.Open Filename:=MyFolder & “\” & MyFile

    Range(Selection, Selection.End(xlDown)).Select
    Application.DisplayAlerts = False

    erow = Range(“A” & Rows.Count).End(xlUp).Offset(1).Select
    Application.CutCopyMode = False
    MyFile = Dir
    End Sub

  5. Neetu Kashyap

    Hi I want to copy the entire row based on criteria , cell value start “C” or “E” and from letf and secound criteria in Another cell value is “C” or “D” then copy the entire row on paste on next visible row
    and applyed this code but is not working plz help

  6. Darren

    Hi. I want to do a search of multiple values and paste it on the new worksheet.


    Instead of just Car, I want to search for Ship, Boat, or even more than 1 value (Ship, Boat or Ship, Car or Car, Boat ) with a comma (,) in between.

    How do search for part of the word and not the exact word?

  7. Amy Zoltek

    I have a workbook with information tracking profit loss. The worksheet has 15 columns and the data starts in A7. There are column headers. I need to copy and paste all of the information to a new spreadsheet for reporting. I’m trying to write a macro so the report will run and take all of the information listed and put into a new workbook.

    The issue that I may run into is the entries are tracked by booking numbers. The numbers can be listed numberous time if there are multiple errors in a booking so there will be duplicates. But they run these reports weekly and I don’t want the data to be exported multiple times.

    There are separate tabs for each month. I would like it to stay that way.

  8. m

    hi sir
    This code (in video link) is not working – it is showing a ‘Run time error’ and saying “Object required”
    can you please kindly help & suggest. thanks

  9. Matt

    Thanks for this, it was very useful.

    Can i ask how you would include paste special rather than just paste. Specifically im looking for values and number formats. I have tried to amend it but doesn’t seem to like anyway i try.



Leave a Reply

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