Sub CalculateTotalHrs()
Dim ShObj As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim TotalKPIHrs As String
Dim TotalActualHrs As String
Set ShObj = ThisWorkbook.Worksheets("Detail Task")
FirstRow = 7
LastRow = ShObj.Cells(FirstRow, 2).End(xlDown).Row - 1
TotalKPIHrs = Application.WorksheetFunction.Sum(ShObj.Range(ShObj.Cells(FirstRow, 8), ShObj.Cells(LastRow, 8)))
TotalActualHrs = Application.WorksheetFunction.Sum(ShObj.Range(ShObj.Cells(FirstRow, 9), ShObj.Cells(LastRow, 9)))
ShObj.Cells(LastRow + 1, 2) = "Total Hours"
ShObj.Cells(LastRow + 1, 2).Font.Bold = True
ShObj.Cells(LastRow + 1, 8) = TotalKPIHrs
ShObj.Cells(LastRow + 1, 9) = TotalActualHrs
ShObj.Range(ShObj.Cells(LastRow + 1, 8), ShObj.Cells(LastRow + 1, 9)).Font.Bold = True
ShObj.Range(ShObj.Cells(LastRow + 1, 2), ShObj.Cells(LastRow + 1, 10)).Interior.ColorIndex = 15
End Sub
|