• Status: Solved
• Priority: Medium
• Security: Public
• Views: 368

# macro to fill down range in different workbooks

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
CC10
• 2
• 2
1 Solution

Commented:
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 Commented:
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

Commented:
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 Commented:
Perfect. Thanks very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.