Solved

macro to fill down range in different workbooks

Posted on 2014-02-05
4
357 Views
Last Modified: 2014-02-05
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
Comment
Question by:CC10
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
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

Open in new window

Regards
0
 

Author Comment

by:CC10
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.

Sorry about that.
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 400 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

Open in new window

Regards
0
 

Author Closing Comment

by:CC10
ID: 39836510
Perfect. Thanks very much
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now