Sub SumCells()
Application.ScreenUpdating = False
Dim LastRow As Long, response As String
response = InputBox("Enter the job function.")
If response = "" Then
MsgBox ("You have not entered a job function.")
Application.ScreenUpdating = True
Exit Sub
End If
If WorksheetFunction.CountIf(Range("D:D"), response) = 0 Then
MsgBox ("The job function entered was not found. Please try again.")
Application.ScreenUpdating = True
Exit Sub
End If
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A1:J" & LastRow).AutoFilter Field:=2, Criteria1:=">" & Date - 45
Range("A1:J" & LastRow).AutoFilter Field:=4, Criteria1:=response
If Range("A2", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row = 1 Then
MsgBox ("There are no " & response & " job functions for new hires.")
Else
If WorksheetFunction.CountA(Range("E2:E" & LastRow).SpecialCells(xlCellTypeVisible)) > 0 Then
Range("M49") = WorksheetFunction.Sum(Range("E2:E" & LastRow).SpecialCells(xlCellTypeVisible))
End If
End If
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Range("A1:J" & LastRow).AutoFilter Field:=2, Criteria1:="<=" & Date - 45
Range("A1:J" & LastRow).AutoFilter Field:=4, Criteria1:=response
If Range("A2", Cells(Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1, 1).Row = 1 Then
MsgBox ("There are no " & response & " job functions for tenured employees.")
Else
If WorksheetFunction.CountA(Range("E2:E" & LastRow).SpecialCells(xlCellTypeVisible)) > 0 Then
Range("M26") = WorksheetFunction.Sum(Range("E2:E" & LastRow).SpecialCells(xlCellTypeVisible))
End If
End If
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub