Consolidate workbooks into one workbook

asudevils5150

New Member
Joined
Feb 19, 2002
Messages
49
Is there a macro to conslidate let's say 3 workbooks into one workbook. Also, let's assume the each workbook has 5 sheets within each book. I'd like to have the new workbook have each sheet separately. Then I have a macro to combine each sheet into one sheet. Ultimately, I'd like to consolidate each worksheet from various workbooks into one master sheet (within a new workbook).

Any help is greatly appreciated
 
I'm thinking more of blank cells. If I had to pick one, then definitely blank rows over the columns based on your analysis.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
How about this ?

Sub CopyAllOpenBooksVer2()
Dim Sh As Worksheet
Dim Wb As Workbook
For Each Wb In Workbooks
If Not Wb.Name = ThisWorkbook.Name Then
For Each Sh In Wb.Worksheets
On Error Resume Next
ConstRng = Sh.Cells.SpecialCells(xlCellTypeConstants, 3).Address
On Error Resume Next
FormRng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 3).Address
If FormRng = "" Then FormRng = ConstRng
If ConstRng = "" Then ConstRng = FormRng

If Not FormRng = "" And Not ConstRng = "" Then
Union(Sh.Range(FormRng), Sh.Range(ConstRng)).EntireRow.Copy
Range("A" & Cells.SpecialCells(xlCellTypeLastCell).Row + 1).PasteSpecial _
Paste:=xlPasteValues
End If
Next Sh
End If ' WB name not this one
Next Wb
End Sub
 
Upvote 0
VERSION 3

Take out blanks and add sheet and book names to column z and y

Sub CopyAllOpenBooksVer3()
Dim Sh As Worksheet
Dim Wb As Workbook
For Each Wb In Workbooks
If Not Wb.Name = ThisWorkbook.Name Then
For Each Sh In Wb.Worksheets
On Error Resume Next
ConstRng = Sh.Cells.SpecialCells(xlCellTypeConstants, 3).Address
On Error Resume Next
FormRng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 3).Address
If FormRng = "" Then FormRng = ConstRng
If ConstRng = "" Then ConstRng = FormRng

If Not FormRng = "" And Not ConstRng = "" Then
Start = Cells.SpecialCells(xlCellTypeLastCell).Row + 1
Union(Sh.Range(FormRng), Sh.Range(ConstRng)).EntireRow.Copy
Range("A" & Start).PasteSpecial Paste:=xlPasteValues

' PLACE BOOK NAME IN COLUMN Z AND SHEET NAME IN COLUMN Y
Range("Z" & Start & ":Z" & Cells.SpecialCells(xlCellTypeLastCell).Row) = Wb.Name
Range("Y" & Start & ":Y" & Cells.SpecialCells(xlCellTypeLastCell).Row) = Sh.Name

End If
Next Sh
End If ' WB name not this one
Next Wb
End Sub
 
Upvote 0
Thanks so much again!! On the previous macro, again, how do i copy the formulas instaed of the values. Do i just replace a few words? YOur help again is greatly appreciated.
 
Upvote 0
Thanks again. I haven't tested the macro yet, but does it take into account transferring the formulas..for instance, if i have a cell in date format, the previous version had converted that cell into that weird five digit date thingie...

Thanks Nimrod
 
Upvote 0
Hello,

As you can tell, I'm working on a big project. Your first code worked great, but for some reason, the next 2 did not work out for me. But that's most likely my error, not yours. Anyways, if we can work on the first code you gave, how do i add the "Tracking Column" in let's say Columns Z and Y as you wrote in the second code. I tried to just copy those three lines into the first code, but got an error. If I can just copy those three lines, where would i place them within the first code.

As for the other post you did on the "collect from and xls directory", that's way complicated for me. I'm a beginner in this VBA code, but I'm trying to learn quickly.

Thanks again. Your response would be greatly appreciated. To summarize, i just want to add the source columns to the first code you wrote. I'll worry about getting blank cells and rows/columns later
 
Upvote 0
The date issue has got to do with the cell format. So I've included a line of code to copy over the format as well as the values from a cell. The current version has been tweeked ohter ways as well so please give it a try . If it doesn't work could you give me a little detail of what's happening.
Also make sure that all xls sheets are open in the same "instance" of excel. That is to say you should be able to goto the Window command on the tool bar and see a list of the books , including the one with the code.

Sub CopyAllOpenBooksVer4()
Dim Sh As Worksheet
Dim Wb As Workbook
For Each Wb In Workbooks
If Not Wb.Name = ThisWorkbook.Name Then
For Each Sh In Wb.Worksheets
On Error Resume Next
ConstRng = Sh.Cells.SpecialCells(xlCellTypeConstants, 3).Address
On Error Resume Next
FormRng = Sh.Cells.SpecialCells(xlCellTypeFormulas, 3).Address
If FormRng = "" Then FormRng = ConstRng
If ConstRng = "" Then ConstRng = FormRng

If Not FormRng = "" And Not ConstRng = "" Then
Start = Cells.SpecialCells(xlCellTypeLastCell).Row + 1
Union(Sh.Range(FormRng), Sh.Range(ConstRng)).EntireRow.Copy
Range("A" & Start).PasteSpecial Paste:=xlPasteValues
Range("A" & Start).PasteSpecial Paste:=xlPasteFormats


' PLACE BOOK NAME IN COLUMN X AND SHEET NAME IN COLUMN Y
Range("Z" & Start & ":Z" & Cells.SpecialCells(xlCellTypeLastCell).Row) = Wb.Name
Range("Y" & Start & ":Y" & Cells.SpecialCells(xlCellTypeLastCell).Row) = Sh.Name
FormRng = ""
ConstRng = ""
End If
Next Sh
End If ' WB name not this one
Next Wb
End Sub
 
Upvote 0
Hello again.

I tried the Macro, but for some reason, it actually copied the text of the subroutine on the workbook. I'm using Excel 97...does that help you any?

Thanks,
Ron
 
Upvote 0

Forum statistics

Threads
1,216,360
Messages
6,130,175
Members
449,562
Latest member
mthrasher16

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