Nested IF statements to analyze time data

Darren_workforce

Board Regular
Joined
Oct 13, 2022
Messages
146
Office Version
  1. 365
Platform
  1. Windows
Hello,

My sheet has shift start times down Column B and shift end times down Column C. (Column A has the names of staff). We open at 8:00:00am and close at 6:00:00pm. I have the following statement in Column D but am missing crucial pieces and am just uncertain where/what to add. I would like to generate 1 of 3 results in Column D based on the start/end times: (Opener, Closer, Mid).

If the time in Column B (start) is earlier than 9:00:00am, an agent is considered an Opener (as long as their end time is earlier or equal to 5:45:00pm).
If the time in Column C (end) is later than 5:45:00pm, the agent is considered a Closer (as long as their start time is later or equal to 9:00:00am).
However, if neither of these conditions are true and the agent arrives after 9:00:00am but also leaves prior to 5:45:00pm, they're considered a Mid-shifter.

Excel Formula:
=IF(AND($B2<=TIMEVALUE("9:00:00"),$C2<=TIMEVALUE("18:00:00")),"Opener","Closer")

I get tripped up with IF statements so any help would be greatly appreciate. Thank you in advance!!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What about you give us with XL2BB 6 or 8 varied rows of data with the results manually filled in and explain again in relation to that specific sample data?
 
Upvote 0
I'm not certain how to generate the format you're requesting (apologies for that) but would a screenshot work?
1712278099663.png

If the time in Column B is earlier than 9:00:00am, an agent is considered an Opener (but they would also require an end time earlier than or equal to 5:45:00pm).
If the time in Column C is later than 5:45:00pm, the agent is considered a Closer (as long as their start time is later than or equal to 9:00:00am).
However, if neither of these conditions are true and the agent arrives after 9:00:00am but also leaves prior to 5:45:00pm, they're considered a Mid-shifter.

Rows 6:9,14:15 - Column D is incorrect because the start time is after that of an Opener (< 9:00:00am) and their end times are earlier than a Closer (> 5:45:00pm) so they would be a Mid.

I know I'm missing the "Mid" portion of the formula but I'm just not certain where it should be applied in the actual formula.
Excel Formula:
=IF(AND($B2<=TIMEVALUE("9:00:00"),$C2<=TIMEVALUE("18:00:00")),"Opener","Closer")
 

Attachments

  • 1712277988581.png
    1712277988581.png
    11.4 KB · Views: 12
Upvote 0
I'm not certain how to generate the format you're requesting
Did you follow the link that I provided?

but would a screenshot work?
Not so good because we cannot copy from that.


(but they would also require an end time earlier than or equal to 5:45:00pm).
What happens if that is not the case? Can't see any examples with B before 9am and C after 5:45pm

If the time in Column C is later than 5:45:00pm, the agent is considered a Closer (as long as their start time is later than or equal to 9:00:00am).
Sam as above, what happens if C > 5:45pm and B < 9:00am? Can't see any examples like that.


Rows 6:9,14:15 - Column D is incorrect
If you filled in all results manually with the results you do want (as requested) and not with a formula that does not do what you want it would be better.
 
Upvote 0
Did you follow the link that I provided?
I did but when attempting to run the add-in I get a popup: This file type is not supported in Protected View. It's a work PC so it may be locked down by my IT team.

Not so good because we cannot copy from that.
I know it's asking more of those offering help but can a variation be manually created on your end to simulate my file with the data I provided.


What happens if that is not the case? Can't see any examples with B before 9am and C after 5:45pm
Nobody has a shift longer than 8 hours so there wouldn't ever be a need to have a start time earlier than 9:00am AND an end time after 5:45pm. If that ever did occur, I could always just manually enter the desired results into the respective D cell.

Sam as above, what happens if C > 5:45pm and B < 9:00am? Can't see any examples like that.
No examples as explained previously.


If you filled in all results manually with the results you do want (as requested) and not with a formula that does not do what you want it would be better.
The results for the most part are what I'm looking for but for those that are wrong, they would all be considered Mid-shifters due to not having neither a start nor end time that falls within the ranges mentioned previously.
 
Upvote 0
I feel like I setup the formula correctly. I tested it and it works for the most part. However, when no time data is provided (the blank rows), it should return a value of "" (nothing). What's wrong below?
Excel Formula:
=IF(AND($B2>TIMEVALUE("8:30"),$C2<TIMEVALUE("17:45")),"Mid",IF(AND($B2>TIMEVALUE("8:30"),$C2>=TIMEVALUE("17:45")),"Closer",IF(AND($B2<=TIMEVALUE("8:30"),$C2<TIMEVALUE("18:00")),"Opener","")))
1712347658340.png
 
Upvote 0
VBA Code:
=IF(OR($B2="",$C2=""),"",IF(AND($B2<TIMEVALUE("9:00"),$C2<=TIMEVALUE("17:45")),"Opener",IF(AND($C2>TIMEVALUE("17:45"),$B2>=TIMEVALUE("09:00")),"Closer",IF(AND($B2>TIMEVALUE("9:00"),$C2<TIMEVALUE("17:45")),"mid","?"))))
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top