Copying and Pasting Between Different Workbooks

tobermory

New Member
Joined
Jun 4, 2012
Messages
46
Hi all,

I have a 'holding' spreadsheet, which basically holds all my necessary macros.

A lot of these macros, involves copying and pasting between different different workbooks, on a monthly basis, and the file name of the book includes the month I'm working on, and is often dynamic from month to month anyway. For example...

Windows("Data Apr18.xlsx").Activate
Sheets("Data").Select
Range("L2:L20001").Select
Selection.Copy
Windows("Data2 Apr18 v1.xlsx").Activate
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

This means I have to go into my macros and replace workbook names it copy/pastes from, every month.

Would there be a more user friendly way around this?

I'm not sure how feasible this is, but I was thinking if the name of one workbook was in Cell A1 (Sheet1), with the name of the second workbook in Cell A2 (Sheet1).
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If you always run macro at mid month then this should work.
Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Workbooks("Data " & Format(Date, "mmmyy") & ".xlsx").Sheets("Data")
Set sh2 = Workbooks("Data2 " & Format(Date, "mmmyy") & "v1.xlsx").Sheets(1)
sh1.Range("L2:L20001").Copy
sh2.Range("B2").PasteSpecial xlPasteValues
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,959
Messages
6,175,647
Members
452,663
Latest member
MEMEH

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