Sub updateTotals()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim wkbSource As Workbook, sPath As String
Dim lCol As Long, desWs As Worksheet, srcWS As Worksheet, fDateCol As Long, x As Long, y As Long, strdate As String
y = 4
Set desWs = ThisWorkbook.Sheets("Summary")
desWs.Range("D5:PW14").ClearContents
'Const strPath As String = "C:\Project Models\"
Const strPath As String = "C:\Forum Help\Yukon\"
ChDir strPath
strExtension = Dir(strPath & "*.xlsx")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
Set srcWS = Sheets("Monthly Cash Flow")
With srcWS
.Range("B1").Formula = "=TEXT(LEFT(D2,FIND(""/"",TEXT(D2,""mm/dd/yyyy""),4)),""mm/dd/yy"")"
strdate = .Range("B1")
lCol = desWs.Cells(1, desWs.Columns.Count).End(xlToLeft).Column - 1
fDateCol = desWs.Rows(2).Find(Format(.Range("B1").Value2, "m/dd/yy"), LookIn:=xlValues, lookat:=xlWhole).Column
With desWs
.Cells(5, fDateCol) = .Cells(5, fDateCol) + srcWS.Cells(5, 3) + srcWS.Cells(5, 4)
.Cells(6, fDateCol) = .Cells(6, fDateCol) + srcWS.Cells(6, 3) + srcWS.Cells(6, 4)
.Cells(7, fDateCol) = .Cells(7, fDateCol) + srcWS.Cells(7, 3) + srcWS.Cells(7, 4)
.Cells(8, fDateCol) = .Cells(8, fDateCol) + srcWS.Cells(8, 3) + srcWS.Cells(8, 4)
End With
For x = fDateCol + 1 To lCol
With desWs
On Error Resume Next
.Cells(5, x) = .Cells(5, x) + srcWS.Cells(5, y)
.Cells(6, x) = .Cells(6, x) + srcWS.Cells(6, y)
.Cells(7, x) = .Cells(7, x) + srcWS.Cells(7, y)
.Cells(8, x) = .Cells(8, x) + srcWS.Cells(8, y)
y = y + 1
End With
Next x
End With
y = 4
wkbSource.Close False
strExtension = Dir
Loop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Bookmarks