A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Try the following:
Option Explicit
Sub ConsolidateInfoSheets()
Dim FolderPath As String
Dim FileName As String
Dim SourceWB As Workbook
Dim SourceWS As Worksheet
Dim DestWB As Workbook
Dim DestWS As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim DestRow As Long
Dim FirstPaste As Boolean
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Folder containing the workbooks
FolderPath = "C:\YourFolderPath\"
'Create new workbook for consolidated data
Set DestWB = Workbooks.Add
Set DestWS = DestWB.Sheets(1)
DestWS.Name = "Info"
DestRow = 1
FirstPaste = True
'Loop through all Excel files in folder
FileName = Dir(FolderPath & "*.xlsx")
Do While FileName <> ""
'Skip the destination workbook if saved in same folder
If FileName <> DestWB.Name Then
Set SourceWB = Workbooks.Open(FolderPath & FileName)
'Loop through all sheets
For Each SourceWS In SourceWB.Worksheets
'Check if sheet name starts with "Info"
If Left(SourceWS.Name, 4) = "Info" Then
With SourceWS
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
'Copy headers only once
If FirstPaste Then
.Range(.Cells(1, 1), .Cells(LastRow, LastCol)).Copy _
DestWS.Cells(DestRow, 1)
DestRow = DestWS.Cells(DestWS.Rows.Count, 1).End(xlUp).Row + 1
FirstPaste = False
Else
'Skip header row after first sheet
If LastRow > 1 Then
.Range(.Cells(2, 1), .Cells(LastRow, LastCol)).Copy _
DestWS.Cells(DestRow, 1)
DestRow = DestWS.Cells(DestWS.Rows.Count, 1).End(xlUp).Row + 1
End If
End If
End With
End If
Next SourceWS
SourceWB.Close SaveChanges:=False
End If
FileName = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Info sheets consolidated successfully!"
End Sub
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin