ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   COMBINING WORKBOOKS (https://www.excelbanter.com/excel-programming/413029-combining-workbooks.html)

lmarstin

COMBINING WORKBOOKS
 
I have 32 workbooks with 3 worksheets each. Each worksheet in each workbook
is named the same. I need to combine all 32 workbooks into one files with
each of the 3 sheets moved. This will make for a total of 96 sheets. I
really don't want to have to open each file and copy the worksheets to a
master sheet.

Cush

COMBINING WORKBOOKS
 
Try something like:

Option Explicit

Sub CopySheets()
Dim Wb As Workbook
Dim i As Integer
Dim j As Integer

On Error Resume Next
''GET THE FIRST WB
Set Wb = Workbooks.Open(Dir(ThisWorkbook.Path & "\*.xls"))
For i = 1 To 3
Wb.Sheets(i).Copy After:=ThisWorkbook.Sheets(1)
Next i
Wb.Close False

''GET REMAINING WBKS
For j = 1 To 32
If Wb.Name < ThisWorkbook.Name Then
Set Wb = Workbooks.Open(Dir)
For i = 1 To 3
Wb.Sheets(i).Copy After:=ThisWorkbook.Sheets(1)
Next i
Wb.Close False
End If
Next j

Set Wb = Nothing

End Sub

"lmarstin" wrote:

I have 32 workbooks with 3 worksheets each. Each worksheet in each workbook
is named the same. I need to combine all 32 workbooks into one files with
each of the 3 sheets moved. This will make for a total of 96 sheets. I
really don't want to have to open each file and copy the worksheets to a
master sheet.



All times are GMT +1. The time now is 11:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com