Sub Disp()
Application.ScreenUpdating = False
Dim DirList As Variant
Dim PresentDir As String
Dim FileList() As Variant
Dim fileName() As Variant
Dim BaseDir As String
Dim ExtractFile As String
Dim CurFile As String
Dim PolHolder As String
Dim Results(24) As Double
Dim AgeDay As Integer
On Error Resume Next
'----- Clear Report Sheet ---------------------------------------
If Sheets("Settings").Range("ClearRep").value = "Prompt" Then
ClearInd = MsgBox("Clear Report ?", vbYesNo, "Clear Report")
If ClearInd = vbYes Then
ClearReport
End If
ElseIf Sheets("Settings").Range("ClearRep").value = "Yes" Then
ClearReport
End If
'----------------------------------------------------------------
'----- Clear Summary Sheet --------------------------------------
If Sheets("Settings").Range("ClearSum").value = "Prompt" Then
ClearInd = MsgBox("Clear Summary ?", vbYesNo, "Clear Summary")
If ClearInd = vbYes Then
ClearOutput
End If
ElseIf Sheets("Settings").Range("ClearSum").value = "Yes" Then
ClearOutput
End If
'----------------------------------------------------------------
'----- Main Extraction Code -------------------------------------
StartDate = Sheets("Settings").Range("StartDate").value
BaseDir = Sheets("Settings").Range("BaseDir").value
ExtractFile = Sheets("Settings").Range("ExtractFile").value
DirList = GetFileList(BaseDir & "\*", vbDirectory)
i2 = 0
'Loop through all directory
For i = LBound(DirList) To UBound(DirList)
Attr = GetAttr(BaseDir & "\" & DirList(i))
If DirList(i) <> "." And DirList(i) <> ".." _
And Attr <> vbArchive _
And Attr <> vbNormal Then
i2 = i2 + 1
Sheets("Output").Cells(i2 + 5, 1).value = DirList(i)
Sheets("Report").Cells(i2 + 3, 1).value = i2
Sheets("Report").Cells(i2 + 3, 2).value = DirList(i)
For z = 1 To 24
Results(z) = 0
Next
PresentDir = DirList(i)
'~~~ Look within all subfolders in directory ~~~
Set fs = Application.FileSearch
With fs
.LookIn = BaseDir & "\" & PresentDir & "\"
.SearchSubFolders = True
.fileName = ExtractFile & "*.*"
If .Execute > 0 Then
masterFound = .FoundFiles.Count
ReDim Preserve FileList(1 To .FoundFiles.Count)
For x = 1 To .FoundFiles.Count
FileList(x) = .FoundFiles(x)
Next x
Else
masterFound = 0
End If
End With
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For j = 1 To masterFound
CurFile = FileList(j)
CurFileName = ShowFileName(CurFile)
MasterModifiedDate = ShowFileModifiedInfo(CurFile)
'Open Workbook
Workbooks.Open CurFile, 0, True
If DoesSheetExists("Client") Then
Sheets("Client").Activate
'~~~ Search through sheet ~~~
x = Cells.Find(What:="?*/?*/????", After:=ActiveCell, SearchDirection:=xlNext).Activate
If x Then
StartAddr = ActiveCell.Address
Do
AgeDay = Max(0, StartDate - ActiveCell.value)
Results(Min(Int(Max(0, AgeDay - 1) / 30) + 1, 12)) = Results(Min(Int(Max(0, AgeDay - 1) / 30) + 1, 12)) + _
Cells(ActiveCell.Row, ActiveCell.Column + 6).value
Results(Min(Int(Max(0, AgeDay - 1) / 30) + 1, 12) + 12) = Results(Min(Int(Max(0, AgeDay - 1) / 30) + 1, 12) + 12) + _
Cells(ActiveCell.Row, ActiveCell.Column + 7).value
x = Cells.Find(What:="?*/?*/????", After:=ActiveCell, SearchDirection:=xlNext).Activate
Loop While x And ActiveCell.Address <> StartAddr
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End If
Workbooks(CurFileName).Close False
Next j
If masterFound = 1 Then
Sheets("Report").Cells(i2 + 3, 3).value = "Y"
Sheets("Report").Cells(i2 + 3, 4).value = MasterModifiedDate
ElseIf masterFound > 1 Then
Sheets("Report").Cells(i2 + 3, 3).value = masterFound
Else
Sheets("Report").Cells(i2 + 3, 3).value = "N"
End If
For i3 = 1 To 12
Sheets("Output").Activate
Cells(i2 + 5, i3 + 1).value = Results(i3)
Cells(i2 + 5, i3 + 14).value = Results(i3 + 12)
Cells(i2 + 5, 27).value = "=SUM(RC[-25]:RC[-14])-SUM(RC[-12]:RC[-1])"
Cells(i2 + 5, 28).value = "=IF(SUM(RC[-26]:RC[-21])>=RC[-1],""Y"",""N"")"
Cells(i2 + 5, 29).value = "=IF(SUM(RC[-27]:RC[-18])>=RC[-2],""Y"",""N"")"
Next
End If
Next i
End Sub