Consolidating two WBs using Macro

haleybusche

New Member
Joined
Mar 7, 2011
Messages
13
I have two workbooks (WB), A and B. Each has as single worksheet, so I will refer to them as WB A and WB B as there is only one worksheet in each. Each has a dynamic number of rows, A as well as B. The contents of each column is of the same type.

What I need is a macro that will combine the information from WB A column 1 and WB B column 1 to be in row 1 and 2 of Column 1 in a separate combined WB. Continued for a set number of columns (9).

So if I have 3 rows in WB A and 5 rows in WB B I should have 8 rows in the combined WB. But the number of rows in WB A and B will change dynamically, and I will need the combined workbook to accommodate this.

Thanks.
 
Last edited:
Actually, when the macro is run again, it should...

1) clear all cells from the destination sheet

2) copy the data from the first source workbook (original data, plus any new data)

3) copy the data from the second source workbook (original data, plus any new data)

Is this not the case?
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
It seems to work sporadically. When I just tried it again, it worked. Then I changed a few things in the separate WBs saved, and tried to run the macro to update the combined workbook and it did not update. The new row I added in one of the separate workbooks did not appear in the combined workbook.
 
Last edited:
Upvote 0
After more testing it appears it doesn't add the last line. So if I add a row at the bottom of WB A or B it won't add it in the combined WB. If I add in the middle it will copy and paste correctly. It appears to be erasing and pasting, but it doesn't copy the new last line and paste it to the combined WB. Any ideas?
 
Upvote 0
When entering a new row of data, if no data is entered in Column A, the new row will not be copied. Therefore, try the following instead...

Code:
[font=Verdana]    [color=darkblue]With[/color] wksA
        [color=darkblue]With[/color] .UsedRange
            LastRow = .Rows.Count + .Rows(1).Row - 1
        [color=darkblue]End[/color] [color=darkblue]With[/color]
        .Range("A2:I" & LastRow).Copy _
            Destination:=wksDest.Cells(wksDest.Rows.Count, "A").End(xlUp).Offset(1)
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
    [color=darkblue]With[/color] wksB
        [color=darkblue]With[/color] .UsedRange
            LastRow = .Rows.Count + .Rows(1).Row - 1
        End [color=darkblue]With[/color]
        .Range("A3:I" & LastRow).Copy _
            Destination:=wksDest.Cells(wksDest.Rows.Count, "A").End(xlUp).Offset(1)
    End [color=darkblue]With[/color]
    [/font]
 
Upvote 0

Forum statistics

Threads
1,215,694
Messages
6,126,250
Members
449,305
Latest member
Dalyb2

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