lucius1707
New Member
- Joined
- Dec 23, 2016
- Messages
- 3
I'm using the macro below to try to consolidate 4000+ files, but i need to be able to consolidate reports that are divided by the same sheet name in each file (around 8).
What do i need to change so i can input the sheet name that i want and then excel consolidate just the reports from this specific sheet in the big file?
Thank you guys very much!
Merry Christmas
What do i need to change so i can input the sheet name that i want and then excel consolidate just the reports from this specific sheet in the big file?
Thank you guys very much!
Merry Christmas

Code:
Option Explicit
Sub ConsolidateAll()
Dim wkbConsol As Workbook
Dim wksConsol As Worksheet
Dim wkbOpen As Workbook
Dim wksOpen As Worksheet
Dim FolderName As String
Dim FileName As String
Dim Cnt As Long
Application.ScreenUpdating = False
Application.StatusBar = "Please wait..."
Set wkbConsol = ActiveWorkbook
Set wksConsol = wkbConsol.Worksheets(1)
'Change the path accordingly
FolderName = "C:\Users\212465810\Box Sync\Fiscalização TP - 2013\PRL"
If Right(FolderName, 1) <> "\" Then FolderName = FolderName & "\"
FileName = Dir(FolderName & "*.xls")
Cnt = 1
Do While FileName <> ""
If FileName <> wkbConsol.Name Then
Application.StatusBar = "Opening " & FileName & "..."
Set wkbOpen = Workbooks.Open(FolderName & FileName)
Set wksOpen = wkbOpen.Worksheets(2)
Application.StatusBar = "Copying the data from " & FileName & "..."
With wksOpen.UsedRange
If Cnt = 1 Then
.Copy
wksConsol.Cells(1, "A").PasteSpecial Paste:=xlPasteValues
Else
.Offset(1, 0).Resize(.Rows.Count - 1).Copy
wksConsol.Cells(wksConsol.Rows.Count, "A").End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
End If
End With
wkbOpen.Close savechanges:=False
Application.StatusBar = FileName & " closed..."
End If
FileName = Dir
Cnt = Cnt + 1
Loop
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub