+ Reply to Thread
Results 1 to 7 of 7

Thread: Indicate shift type coresponding to the time of day in a cell...

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Indicate shift type coresponding to the time of day in a cell...

    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.
    Attached Files Attached Files
    Last edited by Alwpg; 01-02-2012 at 06:28 AM.

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,371

    Re: Indicate shift type coresponding to the time of day in a cell...

    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]

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Indicate shift type coresponding to the time of day in a cell...

    Quote Originally Posted by Alwpg
    I have 3 possible shifts...How can I get Cells I1, I2, I3 to display the word "Day" or "Evening" or "Night"?
    Assuming your start times are always one of those three values (as implied)

    I1
    =IF(SUM(D1)=0,"",IF(HOUR(D1)=7,"Day",IF(HOUR(D1)=15,"Evening","Night")))
    copied to I3

  4. #4
    Registered User
    Join Date
    01-02-2012
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Indicate shift type coresponding to the time of day in a cell...

    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.

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Indicate shift type coresponding to the time of day in a cell...

    Perhaps:

    =LOOKUP(MOD(D3*24-7.75,24),{0,8,16},{"Morning","Evening","Night"})

  6. #6
    Registered User
    Join Date
    01-02-2012
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Indicate shift type coresponding to the time of day in a cell...

    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?

  7. #7
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Indicate shift type coresponding to the time of day in a cell...

    In XL Time is a Decimal value (1 = 24 hours, e.g 6:00 = 0.25).

    D3*24
    converts the time units such that an hour becomes 1 rather than 1/24 - e.g 6:00 [0.25] -> 6.0

    D3*24-7.75
    above subtracts 7:45*24 from the resulting value (7:45 being the start of the first shift), e.g:

    7:30 -> 7.5 -> 0

    MOD(D3*24-7.75,24)
    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:

    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...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0