I have 3 possible shifts: Day, Evening & Night.
Days are 7:45-16:00, Evenings are 15:45-24:00 and Nights are 23:45-8:00.
I want a formula that will tell me what shift an employee works based on the start time.
eg.
D3=7:45 AM, F3=4:00 PM (this is a day shift)
D4=3:45 PM, F4=12:00 AM (this is an evening shift)
D5=11:45 PM, F5=8:00 AM (this is a night shift)
How can I get Cell I3 to display the word "Day" or "Evening" or "Night" properly?
I have attached a sample sheet.
thanks.
Last edited by Alwpg; 01-02-2012 at 06:28 AM.
Maybe you can attach a sample workbook so we can see in what formats the values are stored in columns D & F.
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Assuming your start times are always one of those three values (as implied)Originally Posted by Alwpg
I1 =IF(SUM(D1)=0,"",IF(HOUR(D1)=7,"Day",IF(HOUR(D1)=15,"Evening","Night"))) copied to I3
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
as you indicated, that will only work if the start time is exactly 7,15 or 23. I would also like to know the same info if the shift starts a couple hours late, for example.
Perhaps:
=LOOKUP(MOD(D3*24-7.75,24),{0,8,16},{"Morning","Evening","Night"})
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
That works great, thanks. Only one thing...I don't have a clue what it is doing. Would you mind briefly explaining what it is doing?
In XL Time is a Decimal value (1 = 24 hours, e.g 6:00 = 0.25).
converts the time units such that an hour becomes 1 rather than 1/24 - e.g 6:00 [0.25] -> 6.0D3*24
above subtracts 7:45*24 from the resulting value (7:45 being the start of the first shift), e.g:D3*24-7.75
7:30 -> 7.5 -> 0
it is obvious that given the subtraction where the start time < 7:45 we will end up with a negative value and MOD ensures we end up with appropriate remainder, e.g:MOD(D3*24-7.75,24)
7 -> -0.5 -> 23.5
Given the subtraction of 7:45 from our start time we know the "times" of interest become:
07:45 -> 00:00 -> 0
15:45 -> 08:00 -> 8
23:45 -> 16:00 -> 16
For each of the above we have a distinct return type so we add a result_vector so instead of returning 8 we return "Evening" etc...
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks