Sub SumValues()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Val As Range, ws As Worksheet, desWS As Worksheet, srcRng As Range, desRng As Range, i As Long, foundDate As Range
Dim strdate As String, shStart As String, shEnd As String, lCol As Long
Set desWS = Sheets("Summary_Cash_Flow")
lCol = desWS.Cells(1, desWS.Columns.Count).End(xlToLeft).Column - 1
Set desRng = Union(desWS.Range(desWS.Cells(5, 3), desWS.Cells(14, lCol)), desWS.Range(desWS.Cells(18, 3), desWS.Cells(22, lCol)), _
desWS.Range(desWS.Cells(26, 3), desWS.Cells(31, lCol)), desWS.Range(desWS.Cells(35, 3), desWS.Cells(36, lCol)), _
desWS.Range(desWS.Cells(40, 3), desWS.Cells(40, lCol)), desWS.Range(desWS.Cells(44, 3), desWS.Cells(47, lCol)))
shStart = Sheets(2).Name
shEnd = Sheets(Sheets.Count).Name
With desWS
.Range("C2").Formula = "=min('" & shStart & ":" & shEnd & "'!C2)"
desRng.ClearContents
End With
For Each ws In Sheets
If ws.Name Like "*_CF" Then
lCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column - 1
Set foundDate = desWS.Rows(2).Find(What:=Format(ws.Range("C2").Value2, "m/dd/yy"), LookIn:=xlValues, LookAt:=xlWhole)
If Not foundDate Is Nothing Then
Set srcRng = Union(ws.Range(ws.Cells(5, 3), ws.Cells(14, lCol)), ws.Range(ws.Cells(18, 3), ws.Cells(22, lCol)), _
ws.Range(ws.Cells(26, 3), ws.Cells(31, lCol)), ws.Range(ws.Cells(35, 3), ws.Cells(36, lCol)), _
ws.Range(ws.Cells(40, 3), ws.Cells(40, lCol)), ws.Range(ws.Cells(44, 3), ws.Cells(47, lCol)))
End If
For Each Val In srcRng
desWS.Range(Val.Address).Offset(, foundDate.Column - 3).Value = desWS.Range(Val.Address).Offset(, foundDate.Column - 3).Value + Val.Value
Next Val
End If
Next ws
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Bookmarks