Hello Doc,
This macro will copy all the .xls files from a folder. A worksheet with a common name in the workbooks is appended to the summary sheet in the main workbook. The only changes you need make are to the folder name (actually the path) and the name of the common sheet in the other workbooks. The are marked in the code in blue.
'Written: March 10, 2008
'Author: Leith Ross
'Summary: Opens Workbooks of the user's choosing, copies all the information from
' a sheet with a common name, and copies it to a summary sheet in the
' workbook that is running the macro.
Sub SummarizeWorkbooks()
Dim DataSheet As String
Dim FileName As String
Dim FolderName As String
Dim MyFiles As Variant
Dim MyWkb As Workbook
Dim N As Long
Dim NextRow As Long
Dim Wkb As Workbook
DataSheet = "Sheet1"
Set MyWkb = ThisWorkbook
FolderName = "C:\Documents and Settings\Owner\My Documents"
'Find all "xls" file types in the folder
FileName = Dir(MyPath & "\*.xls", vbNormal)
Do While MyName <> ""
ReDim Preserve MyFiles(N)
MyFiles(N) = FileName
N = N + 1
FileName = Dir
Loop
Set SummarySheet = MyWkb.Worksheets("Summary")
With SummarySheet.UsedRange
NextRow = .Rows.Count + .Row
GoSub FreeRows
End With
Application.ScreenUpdating = False
For Each F In MyFiles
Set Wkb = Workbooks.Open(FileName:=F, ReadOnly:=True)
With Wkb.Worksheets(DataSheet)
.UsedRange.Copy Destination:= _
SummarySheet.Cells(NextRow, "A")
NextRow = NextRow + .UsedRange.Rows.Count
GoSub FreeRows
End With
Wkb.Close
Next F
Application.ScreenUpdating = True
Exit Sub
FreeRows:
If NextRow > SummarySheet.Rows.Count Then
MsgBox "Can Not Copy " & DataSheet & " to " & SummarySheet.Name _
& ", Not Enough Rows left.", vbCritical
Exit Sub
End If
Return
End Sub
Sincerely,
Leith Ross
Bookmarks