Copy dynamic range between workbooks

elieprolb

New Member
Joined
Jan 31, 2017
Messages
3
Greetings,

I have three workbooks, containing a similar sheet.
I need to copy a certain range from two workbooks into the third one.

The sheet looks like a calendar, and I fill data in the corresponding cells.

Capture.PNG


Image link: https://www.dropbox.com/s/yztypvbx7b4o7w8/Capture.PNG?dl=0

I have a macro that copies the data from both workbooks, but the way I'm doing it, the 2nd workbook is copying above the data of the first.

The 1st workbook has data from beginning of month til Today().
The 2nd workbook has data starting from tomorrow.
Also Cross-Posted in the following forums:
Macro from 1st workbook:
Code:
Sub TRANSFER()


    Dim y As Workbook
    Dim x As Workbook
    Dim ws As Worksheet
    Dim sh As Worksheet
    Dim rng As Range
    
    ' Current workbook
    Set y = ActiveWorkbook
    
    Application.ScreenUpdating = 0
    
    ' Target workbook
    Set x = Workbooks.Open("Z:\20-Production-Follow up\BVL-CTC-Works Schedule-E.NAJEM-2017.xlsx")
    
    ' Current worksheet
    Set ws = y.Sheets("Schedule")
    
    ' Target worksheet
    Set sh = x.Sheets("Schedule EN")
    
    ' Copying projects list
    Set rng = ws.Range("A5:B400")
    rng.Copy
    x.Sheets("Schedule EN").Range("A5:B400").PasteSpecial xlValues
    Application.CutCopyMode = False
    
    ' Copying data
    Set rng = ws.Range("G5:AK400")
    rng.Copy
    x.Sheets("Schedule EN").Range("G5:AK400").PasteSpecial xlValues
    Application.CutCopyMode = False
    
    x.Save
    x.Close
    
End Sub


Macro from 2nd workbook:
Code:
Sub TRANSFER()


    Dim y As Workbook
    Dim x As Workbook
    Dim ws As Worksheet
    Dim sh As Worksheet
    Dim rng As Range
    
    ' Current workbook
    Set y = ActiveWorkbook
    
    Application.ScreenUpdating = 0
    
    ' Target workbook
    Set x = Workbooks.Open("Z:\20-Production-Follow up\BVL-CTC-Works Schedule-E.NAJEM-2017.xlsx")
    
    ' Current worksheet
    Set ws = y.Sheets("Schedule")
    
    ' Target worksheet
    Set sh = x.Sheets("Schedule EN")
       
    ' Copying data
    Set rng = ws.Range("G5:NR400")
    rng.Copy
    x.Sheets("Schedule EN").Range("G5:NR400").PasteSpecial xlValues
    Application.CutCopyMode = False
    
    x.Save
    x.Close
    
End Sub


You can see that Range("G5:NR400") from 2nd workbook is copying above Range("G5:AK400") from 1st workbook...

How can I alter the copy range code in a way so that:
- from the 1st workbook, the range starts from G5 and ends with the column related to Today()
- from the 2nd workbook, the range starts from Today() + 1 till NR400.

Thanks in advance...

I asked this question on excelforum.com with no luck so far:
Copy dynamic range between workbooks

Also cross-posted in the following forums:
http://www.excelguru.ca/forums/showthread.php?7334-Copy-dynamic-range-between-workbooks
http://www.msofficeforums.com/excel-programming/34106-copy-dynamic-range-between-workbooks.html
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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