Q:

Calculate difference between two times in range of columns

I am trying to calculate the difference between every row A5 to A20 and B5 to B20 and change the color to green if it equals 4 hours. I'm having a hard time setting up a range. I currently can only do one cell at a time.
Sub test()
    Dim Total As Double
    Dim Timein As Date
    Dim Timeout As Date
    Timein = CDate(Range("A7").Value)
    Timeout = CDate(Range("B7").Value)

    Total = 24 * ((Timeout - Timein))
    Debug.Print Total
    Debug.Print Format(Total, "#,##0_);(#,##0)")
    If Total = 4 Then
        Range("A7").Interior.Color = vbGreen
    End If

    Debug.Print "Number of hours = " & Total * 24
End Sub

A:

Why are you even using VBA for this task?  Excel has built-in commands and functionality (conditional formatting) just for things like that.  Using VBA is an overkill.
Sub test()

    Dim dteIn As Date
    Dim dteOut As Date
    Dim rng As Range, cll As Range

    Set rng = Range("A5:A20")

    For Each cll In rng
        dteIn = CDate(cll.Value)
        dteOut = CDate(cll.Offset(0, 1).Value)
        If CInt((dteOut - dteIn) * 24) = 4 Then
            cll.Interior.Color = vbGreen
        End If
    Next

End Sub

