Macro for copying data from one workbook to another under certain conditions

kitkat12

New Member
Joined
Jul 29, 2015
Messages
5
I have two workbooks, Workbook A and Workbook B. Workbook A has data that I need to input into a specific worksheet (let's call it "Data") in Workbook B. The data I need from Workbook A is in A18:AM18. I need it copied into Workbook B in the "Data" worksheet. However I need to do this each month, and the location where the data needs to go changes because it is updated each month. I would like to post the data to the first empty row starting at D and going to AP. In the same row, I would like to input "APAC" into column C, and pull down the existing formulas from the cells above in columns A and B. I also need this to be created into a button so I can just push it each month and the report updates.

Thank you very much for your help in advance!:)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi, Try this. It assumes that workbook B is closed when the macro is run.

Code:
   Workbooks.Open Filename:="I:\_desktop\Workbook B.xlsx"
    Sheets("Data").Select
    ActiveWindow.SmallScroll Down:=-15
    Range("D1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    Windows("Workbook A.xlsx").Activate
    Range("A18:AM18").Select
    Selection.Copy
    Windows("Workbook B.xlsx").Activate
    ActiveSheet.Paste
 
Upvote 0
I'm getting an "Run-time error '1004'". It's telling me that the file in the first line of code cannot be found. I made sure to put the file on my desktop and change the name.
 
Upvote 0
it doesn't need to be on your desktop. The filepath in the code just needs to match the filepath where your spreadsheet was saved. My desktop might be a different filepath to your desktop. E.g. my desktop is on my I: drive but it may be C: drive on your desktop.
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,478
Latest member
Davenil

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