All of the files are in the same folder. Currently I am merging them
all into the same worksheet to consolidate the data.
Is there a question there?
If you're looking for a way to automate the merging, here's one way:
Public Sub MergeFolderToWorkbook()
Const MYFOLDER As String = _
"OS X Drive:Users:john
ocuments:XL Scratch:TestFolder:"
Dim fNames() As String
Dim wkbk As Workbook
Dim indexRange As Range
Dim i As Integer
Dim j As Integer
Dim fName As String
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
fName = Dir(MYFOLDER, MacID("XLS8"))
If fName <> "" Then
With Workbooks.Add(xlWBATWorksheet)
.SaveAs FileName:="Consolidation" & _
Format(Date, "yyyymmdd.xl\s")
With .Worksheets(1)
.Range("A1:B1").Value = _
Array("Workbooks", "Sheets")
Set indexRange = .Range("A2")
End With
Do While fName <> ""
i = i + 1
ReDim Preserve fNames(1 To i)
fNames(i) = fName
fName = Dir()
Loop
For i = LBound(fNames) To UBound(fNames)
Application.StatusBar = "Merging File " & i & _
": " & fNames(i)
Set wkbk = Workbooks.Open( _
FileName:=MYFOLDER & fNames(i))
indexRange.Value = "'" & fNames(i)
For j = 1 To wkbk.Worksheets.Count
If Application.CountA( _
wkbk.Worksheets(j).UsedRange) > 0 Then
wkbk.Worksheets(j).Copy _
after:=.Sheets(.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = Left(wkbk.Name, 28) _
& Format(j, "000")
On Error GoTo 0
indexRange.Offset(0, 1) = "'" & _
ActiveSheet.Name
Set indexRange = indexRange.Offset(1, 0)
End If
Next j
wkbk.Close savechanges:=False
Set indexRange = indexRange.Offset(1, 0)
Next i
End With
indexRange.Resize(1, 2).Columns.AutoFit
Else
MsgBox "no XL files found"
End If
With Application
.EnableEvents = True
.DisplayAlerts = True
.StatusBar = False
.ScreenUpdating = True
End With
End Sub