This should do it:
Option Explicit
Sub CollateDatedData()
Dim fPATH As String, fNAME As String, NR As Long, fDate As String
Dim wb As Workbook, ws As Worksheet, wsMaster As Worksheet
On Error GoTo ErrorExit
Application.ScreenUpdating = False 'speed up macro, turn off screen flicker
'make sure master has titles in row1 already
Set wsMaster = ThisWorkbook.Sheets("Master") 'edit to name of sheet for report
fPATH = "S:\Railserve\Availability\" 'remember the final \ in this string
If MsgBox("Clear the current data on the master?", vbYesNo, "Reset Master") = vbYes Then
wsMaster.UsedRange.Offset(1).Clear 'option to clear data, keep titles
NR = 2 'start entering data at row 2
Else
NR = wsMaster.Range("A" & Rows.Count).End(xlUp).Row + 1 'add data to existing data, next row
End If
fNAME = Dir(fPATH & "Availability*.xlsx") 'get the first filename from the fPATH
Do While Len(fNAME) > 0 'process each file one at at time
fDate = Replace(Replace(fNAME, ".xlsx", ""), "Availability", "")
fDate = Left(fDate, 2) & "/" & Mid(fDate, 3, 2) & "/" & Mid(fDate, 5, 2) 'create date string
Set wb = Workbooks.Open(fPATH & fNAME) 'open the found file
wb.Sheets("Car Summary By Product Line").Range("A4:I4").Copy 'copy the date
wsMaster.Range("A" & NR).PasteSpecial xlPasteValues 'paste values only
wsMaster.Range("A" & NR).PasteSpecial xlPasteFormats 'correct formatting
wsMaster.Range("J" & NR).Value = fDate 'add date to column J
wb.Close False 'closed the found file
NR = NR + 1 'increment the next row for data
fNAME = Dir 'get the next filename from FPATH
Loop 'repeat til no more filenames
ErrorExit:
Application.ScreenUpdating = True 'return to normal speed, update screen
End Sub
Bookmarks