Solved

macro to fill down range in different workbooks

Posted on 2014-02-05
4
359 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 49

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 49

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 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