+ Reply to Thread
Results 1 to 6 of 6

Claculate hours between values in one cell

  1. #1
    Registered User
    Join Date
    07-15-2014
    Location
    Adelaide, Australia
    MS-Off Ver
    2007
    Posts
    2

    Smile Claculate hours between values in one cell

    HI,
    is there a way to autocalculate the hours worked between two times in one cell?

    For my work roster i am putting the roster with hours on sheet 1 and then on sheet 2 i would like it to calculate the hours worked.

    For example sheet 1 may have:

    A1 A2
    Staff 1 0800-1400
    Staff 2 1000-1430
    Staff 3 1500-2300
    Staff 4 2000-0800

    And what i want it to do is auto populate into sheet 2 the following:

    A1 A2
    Staff 1 6
    Staff 2 4.5
    Staff 3 8
    Staff 4 12


    Any ideas would be greatly appreciated.

    Thanks

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Claculate hours between values in one cell

    Try this...

    Data Range
    A
    B
    C
    1
    Staff 1
    0800-1400
    6
    2
    Staff 2
    1000-1430
    4.5
    3
    Staff 3
    1500-2300
    8
    4
    Staff 4
    2000-0800
    12


    This formula entered in C1 and copied down:

    =MOD(TEXT(RIGHT(B1,4),"00\:00")-TEXT(LEFT(B1,4),"00\:00"),1)*24
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    07-15-2014
    Location
    Adelaide, Australia
    MS-Off Ver
    2007
    Posts
    2

    Re: Claculate hours between values in one cell

    Thanks Biff that works!!!

    Now to throw a spanner in the works and really test people, am i able to make the formula so that if there is no value in the cell (ie the staff didnt work) the result is 0 instead of 'value'?

    And also if i put in a D or N (representing day or night shift) can this equal 12.25 hours.

    I know i may be asking a bit muc.....

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Claculate hours between values in one cell

    So you want to account for all of those possibilities in the same cell?


    =IF(B1="",0,IF(OR(B1={"D","N"}),12.25,MOD(TEXT(RIGHT(B1,4),"00\:00")-TEXT(LEFT(B1,4),"00\:00"),1)*24))

  5. #5
    Registered User
    Join Date
    03-30-2021
    Location
    London
    MS-Off Ver
    Excel
    Posts
    2

    Re: Claculate hours between values in one cell

    Hi there been a while since this was posted but would this work with multiple 'B' columns, for example monday to sunday, if so how could one do that?

    A1 B1 C1 D1 E1 F1 G1 H1 I1
    Staff Time Time Time Time Time Time Time (C column in your example)

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Claculate hours between values in one cell

    Quote Originally Posted by Phasm Orix View Post
    Hi there been a while since this was posted but would this work with multiple 'B' columns, for example monday to sunday, if so how could one do that?

    A1 B1 C1 D1 E1 F1 G1 H1 I1
    Staff Time Time Time Time Time Time Time (C column in your example)
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Seperate simple hours, holiday hours and night hours
    By enitron in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-27-2014, 07:22 AM
  2. [SOLVED] Calculate hours with predefined Working Hours and Weekend Hours
    By garciapliz in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-05-2013, 11:17 AM
  3. How to claculate number of days worked
    By [email protected] in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-18-2010, 08:17 AM
  4. Summing values for past 24 hours
    By bobhearn11 in forum Excel General
    Replies: 2
    Last Post: 01-08-2010, 04:03 AM
  5. Replies: 2
    Last Post: 05-25-2005, 12:06 PM

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.6.0 RC 1