Forum Discussion

Mohamed Hasan Marie's avatar
Mohamed Hasan Marie
Copper Contributor
Mar 07, 2018
Solved

Transfer data from one workbook to another

Hey guys. Could you please support me to get VBA code for copying data from Worbook X to first empty rowe in workbook Y

  • Hello Mohamed,

     

    Here is the piece of code. This may not be the best effective way, but something that can do the job for you. 

    ' you can amend the A1:Z100 range to whatever is your actual data range

     

    You should put this code in a module of workbook from which you want the data to be copied from.

    it will copy from Sheet1 of thisworkbook into the path and file name and sheet Sheettopasteto

     

     

    Sub CopyfromThisworkbookToANother()
    Workbooks.Open ("C:\Documents\ExcelFiletoPasteDataTo.xlsx") ' you can amend this path and file name to you actual path and file name
    ThisWorkbook.Sheets("Sheet1").Range("A1:Z100").Copy Workbooks("ExcelFiletoPasteDataTo.xlsx").Sheets("Sheettopasteto").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

    End Sub

     

10 Replies

  • Jamil's avatar
    Jamil
    Bronze Contributor

    Hello Mohamed,

     

    Here is the piece of code. This may not be the best effective way, but something that can do the job for you. 

    ' you can amend the A1:Z100 range to whatever is your actual data range

     

    You should put this code in a module of workbook from which you want the data to be copied from.

    it will copy from Sheet1 of thisworkbook into the path and file name and sheet Sheettopasteto

     

     

    Sub CopyfromThisworkbookToANother()
    Workbooks.Open ("C:\Documents\ExcelFiletoPasteDataTo.xlsx") ' you can amend this path and file name to you actual path and file name
    ThisWorkbook.Sheets("Sheet1").Range("A1:Z100").Copy Workbooks("ExcelFiletoPasteDataTo.xlsx").Sheets("Sheettopasteto").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

    End Sub

     

    • Mohamed Hasan Marie's avatar
      Mohamed Hasan Marie
      Copper Contributor

      Thanks you so much Jamil for your quick replay. But unfortunately this code still not working in my sheet

      • Jamil's avatar
        Jamil
        Bronze Contributor

        did you rename the object names from the code to the actual names of your workbooks objects?

         or simply you copied and pasted the code i posted?

         

        Can you tell me what is the name of sheet you are copying from?

        what is the range to copy?

        what is the workbook name to paste to?

        and what is the sheet name to paste to?

        which column it should be pasted to?

        is the workbook you are pasting to, an open workbook, it is saved in a directory folder?

         

Resources