Hello.
Below code consolidates all worksheets in blank workbook, inserts source sheet names in Column A, saves new workbook in the same folder with source workbook.
copy and paste the code in a standard module of the source workbook.
Sub MergeAllWorksheetsInABlankWorkbook()
Dim SummarySheet As Worksheet, SourceSheet As Worksheet
Dim SourceRange As Range, DestRange As Range, Headers As Range
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
SummarySheet.Range("A1").Value = "Worksheet Name"
For Each SourceSheet In ThisWorkbook.Worksheets
Set DestRange = SummarySheet.Range("B" & Rows.Count).End(xlUp).Offset(1)
With SourceSheet.UsedRange
Set Headers = .Rows(1)
Set SourceRange = .Offset(1).Resize(.Rows.Count - 1)
DestRange.Resize(.Rows.Count - 1, .Columns.Count).Value = SourceRange.Value
DestRange.Offset(, -1).Resize(.Rows.Count - 1).Value = .Parent.Name
End With
Next SourceSheet
With SummarySheet
.Range("B1").Resize(, Headers.Columns.Count).Value = Headers.Value
.Columns.AutoFit
.Parent.SaveAs ThisWorkbook.Path & "\summary.xlsx", 51
End With
End Sub
Bookmarks