hmm...try this out. This will combine all the "Sheet1" tabs from the "part books" into one MasterSheet.
Steps to try out:
1- download the "Test.zip" attachment to anywhere.
2- extract the folder "Test".
3- open the file labeled "MasterSheet_WithMacro" and run the macro.
This macro will look to a folder named ComponentSheets for the parts...from that folder it will extract everything from the "sheet1" tabs (of each book) and paste those rows to the "sheet1" tab of the MasterSheet.
Option Explicit
Sub LoopDirectory()
Dim summationBook As Workbook
Dim i As Long, j As Long
Dim sourceBook As Workbook
Dim sourceData As Worksheet
Dim CurrentFileName As String
Dim myPath As String, myData As String
Dim where1 As Range, where2 As Range
'The parts need to be kept in a folder sitting in the same directory as the master sheet
'and the folder should be names ComponentSheets (or name it whatever you like and change
'the appropriate line (2 lines down) to match your choice
myPath = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name))
myPath = myPath & "ComponentSheets"
'Enter the name of the worksheet that contains the data in the separate books
'for the exmample books I left the name as "Sheet1"
myData = "Sheet1"
'Finds the name of the first file of type .xls in the current directory
CurrentFileName = Dir(myPath & "\*.xls")
'Create a workbook for the recap report
Set summationBook = ThisWorkbook
'Clear the summationBook of old data - j marks the end of the collection (on A column).
j = summationBook.Worksheets(myData).Cells(Rows.Count, 1).End(xlUp).Row + 1
summationBook.Worksheets(myData).Range("A2:AA" & j).ClearContents
Do
'************************************************************************
Workbooks.Open (myPath & "\" & CurrentFileName)
Set sourceBook = Workbooks(CurrentFileName)
Set sourceData = sourceBook.Worksheets(myData)
'********************************************************************
'The sourceData will be combed on the "A" column for rows of information
'Each row (starting below row 1) will be copied to the next available row
'in the summary book.
For i = 2 To sourceData.Cells(Rows.Count, 1).End(xlUp).Row
j = summationBook.Worksheets(myData).Cells(Rows.Count, 1).End(xlUp).Row + 1
sourceData.Range("A" & i & ":AA" & i).Copy Destination:=summationBook.Worksheets(myData).Range("A" & j)
Next i
'********************************************************************
sourceBook.Close
'************************************************************************
'Calling DIR w/o argument finds the next .xlsx file within the current directory.
CurrentFileName = Dir()
Loop While CurrentFileName <> ""
End Sub
Bookmarks