SOLVED

Transfer data from one workbook to another

Copper Contributor

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

10 Replies
best response confirmed by Jamil Mohammad (Bronze Contributor)
Solution

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

 

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

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?

 

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

what is the range to copy? A1:BB1000

what is the workbook name to paste to? Y.xlsx

and what is the sheet name to paste to? Sheet1

which column it should be pasted to? column1

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

 

But you didn't ask about the workbook name which i need to copy date from. name is X.xlsx

My last question.

 

what is the full path/directory string where the WOrkbook Y.xlsx is saved?

 

also your workbook X needs to be saved as Macro Enabled workbook which is xlsm

so that the code can be saved there.   

the 2 files is are saved in same folder

  D:\VBA\X.xlsx   

  D:\VBA\Y.xlsx

 

Thanks Jamil. It's working now. Thanks for your time and support 

You are welcome. I am glad I was able to help. Thanks for feedback.

Jamil. One more thing. If i want to create the code but in the sheet which I need to copy to. Is that possible?

Yes,

 

simply reverse it like this

 

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

End Sub
1 best response

Accepted Solutions
best response confirmed by Jamil Mohammad (Bronze Contributor)
Solution

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

 

View solution in original post