copying and pasting data from one workbook to another

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi, i Have the code below where i want to copy data from "!UPDATEDnew!JM on day (sheet Northants)"and paste into "LATE JM on day (sheet Northants & Bucks)", but the code below isnt working and all it does is close my spreadsheets down. Please can you help me please?

Code:
Private Sub CommandButton7_Click()
Dim x As Workbook
Dim y As Workbook
Dim vals As Variant

'## Open both workbooks first:
Set x = Workbooks.Open("C:\Users\s21375\Desktop\VBA stuff\!UPDATEDnew!JM on day.xlsm")
Set y = Workbooks.Open("C:\Users\s21375\Desktop\VBA stuff\LATE JM on day.xlsm")

'Store the value in a variable:
vals = x.Sheets("Northants").Range("A1").Value

y.Sheets("Northants & Bucks").Range("A1").Value = vals


End Sub
 
If you've changed the name of the folder containing the file, you'll need to change the file path in the code.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi sorry, i did get it working but now its not i don't know what i have done wrong :( i am still a beginner in this and i thank you for your patience, below is the code i have used and the only things i have changed is the main file name to 'Northants JM on day.xlsm' and where i want the data copied from which i have changed to A29. but i want this pasted into A1 on the ' LATE JM on day.xlsm, sheet 'Northants & Bucks'

Code:
Private Sub CommandButton2_Click()
Dim x As Workbook
Dim y As Workbook
Dim vals As Variant

Set x = Workbooks.Open("C:\Users\s21375\Desktop\VBA stuff\Northants JM on day.xlsm")
Set y = Workbooks.Open("C:\Users\s21375\Desktop\VBA stuff\LATE JM on day.xlsm")

x.Sheets("Northants").UsedRange.Copy y.Sheets("Northants & Bucks").Range("A29")

End Sub
 
Upvote 0
How about
Code:
x.Sheets("Northants").Range("A29:J29").Copy y.Sheets("Northants & Bucks").Range("A1")
 
Upvote 0
nope :( i really don't know what i am doing wrong :(, i want to copy from Northants JM on the day sheet 'Northants' from cell A29:J29 then go down until last row, and paste this information into Late 'JM On Day' into sheet 'Northants' cell A1:J1 then go down until last row, sorry about all this, its probably something i am doing my end, :(
 
Upvote 0
Is anything getting copied across?
 
Upvote 0
hi, no nothing at all :( all it does is re-opens the Northants JM on the day.xlsm, i have saved both files and had them open when i click on the commandbutton
 
Upvote 0
Either the files need to be closed when you run the code, or you need to change the code so that you are not opening them.
 
Upvote 0
i closed the LATE JM on day.xlsm and pressed the command button on the Northants JM of the day and still no joy :(, do i not need to pust a .Paste code in anywhere?
 
Upvote 0

Forum statistics

Threads
1,224,835
Messages
6,181,245
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top