This code does it.
Const WORKING_DAY_END As String = "18:00"
Const FORMULA_WORKING_TIME As String = _
"=(INT(E2-D2)*(""" & WORKING_DAY_END & """-""" & WORKING_DAY_START & """)" & _
"+MEDIAN(MOD(E2,1),""" & WORKING_DAY_END & """,""" & WORKING_DAY_START & """)" & _
"-MEDIAN(MOD(D2,1),""" & WORKING_DAY_END & """,""" & WORKING_DAY_START & """))"
Dim lastrow As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "G").End(xlUp).Row
With Range("G2").Resize(lastrow - 1)
.Formula = FORMULA_WORKING_TIME
.Value = .Value
.NumberFormat = "[h]:mm"
End With
End With
I have used all the constants so as to make it easy to amend if the start/end day times change. I have also output the answer as hh:mm as this makes more sense (to me) than decimals.