Create Summary Sheet from Multiple Workbooks with VBA

How to create a summary sheet from multiple workbooks with VBA automatically. An Excel user might have data in hundreds of workbooks in a folder and he would like to create a summary of all the data in his workbooks quickly and automatically. Such data can be invoices, collection of DVDs or books, students’ data, etc. Let’s see how we can summarize such data quickly and easily with VBA by watching the video below:

Watch this video on YouTube.

Here’s the complete VBA code:

Sub createSummarySheet()
Dim SummarySht As Worksheet
Dim FolderPath As String
Dim BlankRow As Long
Dim FileName As String
Dim WorkBk As Workbook
Dim SourceRange As Range
Dim DestRange As Range
Dim lastrow As Long
Set SummarySht = ActiveWorkbook.Worksheets(1)
FolderPath = “C:\TestMF\”
BlankRow = 2
FileName = Dir(FolderPath & “*.xl*”)

Do While FileName <> “”
Set WorkBk = Workbooks.Open(FolderPath & FileName)
SummarySht.Range(“A” & BlankRow).Value = FileName
lastrow = WorkBk.Sheets(“sheet1”).Range(“A” & Rows.Count).End(xlUp).Row
Set SourceRange = WorkBk.Worksheets(1).Range(Cells(2, 1), Cells(lastrow, 2))
Set DestRange = SummarySht.Range(“B” & BlankRow)
Set DestRange = DestRange.Resize(SourceRange.Rows.Count, SourceRange.Columns.Count)
DestRange.Value = SourceRange.Value
BlankRow = BlankRow + DestRange.Rows.Count
WorkBk.Close savechanges:=False
FileName = Dir()

End Sub

Further Reading:

Merging Data from Multiple Workbooks into a Summary Workbook in Excel 2010