This is the code I used in Crystal Reports to do what I am looking for. Not sure how to make this code work in Excel.
Dim dateDif as String
Dim startcode as String
Dim stopcode as String
Dim code as String
Shared ct1 as number
Shared ct2 as number
Shared ct3 as number
Shared ct4 as number
Shared ct5 as number
Shared ct6 as number
ct1 = 0
ct2 = 0
ct3 = 0
ct4 = 0
ct5 = 0
ct6 = 0
'Calculate datedif if start and end on same date = 0 if stop date <> start date = 1
'if {case_.cas_roomstadate} = {case_.cas_roomstpdate} then dateDif = "0" else
' dateDif = "1"
dateDif = cstr(
{@calcdate})
' Calculate start code
if
{@ROOM START TIME} in TimeValue("07:00:00") to TimeValue("14:59:59") then
startcode = "1"
else
if
{@ROOM START TIME} in TimeValue("15:00:00") to TimeValue("16:59:59") then startcode = "2" else
if
{@ROOM START TIME} in TimeValue("17:00:00") to TimeValue("18:59:59") then startcode = "3" else
if
{@ROOM START TIME} in TimeValue("19:00:00") to TimeValue("20:59:59") then startcode = "4" else
if
{@ROOM START TIME} in TimeValue("21:00:00") to TimeValue("23:59:59") then startcode = "5" else
if
{@ROOM START TIME} in TimeValue("00:00:00") to TimeValue("06:59:59") then startcode = "6"
end if
'calculate stop code
if
{@ROOM STOP TIME} in TimeValue("07:00:00") to TimeValue("14:59:59") then stopcode = "1" else
if
{@ROOM STOP TIME} in TimeValue("15:00:00") to TimeValue("16:59:59") then stopcode = "2" else
if
{@ROOM STOP TIME} in TimeValue("17:00:00") to TimeValue("18:59:59") then stopcode = "3" else
if
{@ROOM STOP TIME} in TimeValue("19:00:00") to TimeValue("20:59:59") then stopcode = "4" else
if
{@ROOM STOP TIME} in TimeValue("21:00:00") to TimeValue("23:59:59") then stopcode = "5" else
if
{@ROOM STOP TIME} in TimeValue("00:00:00") to TimeValue("06:59:59") then stopcode = "6"
code = dateDif & startcode & stopcode
' Get out of the routine if Room is cysto, Lith or OR 4
'if {room.rm_room} = "CYSTO 1" then code = "999" else
' if {room.rm_room} = "CYSTO 2" then code = "999" else
' if {room.rm_room} = "LITH" then code = "999" else
' if {room.rm_room} = "OR 4" then code = "999"
' Calculate times
Select Case code
case "011"
ct1 = 1
case "012"
ct1 = 1
ct2 = 1
case "013"
ct1 = 1
ct2 = 1
ct3 = 1
case "014"
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
case "015"
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
case "116"
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
case "111"
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = ct1 + 1
case "022"
ct2 = 1
case "023"
ct2 = 1
ct3 = 1
case "024"
ct2 = (TimeValue("16:59:59")-{@ROOM START TIME})/60
ct3 = 1
ct4 = 1
case "025"
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
case "126"
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
case "121"
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
case "122"
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = ct2 + 1
case "033"
ct3 = 1
case "034"
ct3 = 1
ct4 = 1
case "035"
ct3 = 1
ct4 = 1
ct5 = 1
case "136"
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
case "131"
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
case "132"
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
case "133"
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = ct3 + 1
case "044"
ct4 = 1
case "045"
ct4 = 1
ct5 = 1
case "146"
ct4 = 1
ct5 = 1
ct6 = 1
case "141"
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
case "142"
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
case "143"
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
case "144"
ct4 = 1
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = ct4 + 1
case "055"
ct5 = 1
case "156"
ct5 = 1
ct6 = 1
case "151"
ct5 = 1
ct6 = 1
ct1 = 1
case "152"
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
case "153"
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
case "154"
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
case "155"
ct5 = 1
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = ct5 + 1
case "066"
ct6 = 1
case "061"
ct6 = 1
ct1 = 1
case "062"
ct6 = 1
ct1 = 1
ct2 = 1
case "063"
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
case "064"
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
case "065"
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
case "166"
ct6 = 1
ct1 = 1
ct2 = 1
ct3 = 1
ct4 = 1
ct5 = 1
ct6 = ct6 + 1
case "999"
ct1 = 0
ct2 = 0
ct3 = 0
ct4 = 0
ct5 = 0
ct6 = 0
End Select
formula = code