Sub GetTotals()
Dim rng1 As Range
Dim cell As Range
Dim rt As String
Dim fnd As Range
Dim ct As Integer
Dim tot As Double
Dim lr As Long
Dim rng2 As Range
Application.ScreenUpdating = False
' Get range of values to total (starting in cell C3)
Set rng1 = Range("C3:C" & Range("C2").End(xlDown).Row)
' Loop through all cells in range of values to total
For Each cell In rng1
' Get route number
rt = cell.Value
' Search for route number in column A
Set fnd = Columns("A:A").Find(What:=rt, After:=Range("A1"), LookIn:= _
xlFormulas2, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
' If not found, put 0 for Count and Sum in columns D and E
If fnd Is Nothing Then
cell.Offset(0, 1).Value = 0
cell.Offset(0, 2).Value = 0
Else
' See if any data below heading, and if not, put in zeroes
If fnd.Offset(1, 0) = "" Then
cell.Offset(0, 1).Value = 0
cell.Offset(0, 2).Value = 0
Else
' Find last row in data block
lr = fnd.End(xlDown).Row
' Get counts and sums
Set rng2 = Range(Cells(fnd.Row + 1, "A"), Cells(lr, "A"))
cell.Offset(0, 1).Value = lr - fnd.Row
cell.Offset(0, 2).Value = Application.WorksheetFunction.Sum(rng2)
End If
' Reset found range
Set fnd = Nothing
End If
Next cell
Application.ScreenUpdating = True
MsgBox "Macro complete!"
End Sub