This code just opens the source file but doesn't copy anything from it. I want to copy the data from my source file and paste it to the destination file.
Sub copy()
Dim x As Workbook
Dim y As Workbook
Set x = Workbooks.Open("Source File")
Set y = Workbooks.Open("Destination File")
y.Sheets("Sheet1").Range("A1").Value = x.Sheets("Sheet1").Range("A1")
x.Close
End Sub
You are missing .Value
ant the end of your line:
y.Sheets("Sheet1").Range("A1").Value = x.Sheets("Sheet1").Range("A1").Value
Or Try:
y.Sheets(1).Cells(1, 1).Value = x.Sheets(1).Cells(1, 1).Value
I guess you don't have Sheet1 in both workbook, so lets try different notation.
Try debugging your code with:
msgbox y.Sheets("Sheet1").Range("A1").Value
msgbox x.Sheets("Sheet1").Range("A1").Value
I guess your files are not being opened properly.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments