Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# macro to fill down range in different workbooks

Posted on 2014-02-05
Medium Priority
363 Views
I have 2 workbooks "A" and "B" including 2 sheets with the same name "data".

If the last row in WbA "data" is 250 and the last row in "WbB data" is 200, then the macro should fill down the range "A200-H250" in WbB

Thanks,
CC
0
Question by:CC10
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 52

Expert Comment

ID: 39835891
Hi,

pls try

``````Sub Macro()

LastRowA = Sheets("A").Range("A" & Cells.Rows.Count).End(xlUp).Row
LastRowB = Sheets("B").Range("A" & Cells.Rows.Count).End(xlUp).Row
If LastRowB < LastRowA Then
Sheets("B").Range("A" & LastRowB & ":H" & LastRowA).FillDown
'ElseIf LastRowB > LastRowA Then   ' if reprocicate
'    Sheets("A").Range("A" & LastRowA & ":H" & LastRowB).FillDown
End If

End Sub
``````
Regards
0

Author Comment

ID: 39836248
Hello,  that works fine but I didn't realise that I need to copy the range rather then just fill down.
So if lastrowB is 200 and lastrow A is 250, the macro should copy the range Sheets ("A").Range A200:H250 to Sheets("B") Range A 200:H250

I could just link the ranges with formulas but that takes up space and I would prefer just to copy and paste.

0

LVL 52

Accepted Solution

Rgonzo1971 earned 1600 total points
ID: 39836466
Hi,

pls try
``````Sub Macro1()

LastRowA = Sheets("A").Range("A" & Cells.Rows.Count).End(xlUp).Row
LastRowB = Sheets("B").Range("A" & Cells.Rows.Count).End(xlUp).Row
If LastRowB < LastRowA Then
Sheets("A").Range("A" & LastRowB & ":H" & LastRowA).Copy _
Destination:=Sheets("B").Range("A" & LastRowB)
End If

End Sub
``````
Regards
0

Author Closing Comment

ID: 39836510
Perfect. Thanks very much
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
###### Suggested Courses
Course of the Month8 days, 8 hours left to enroll