+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : formula with constraints

  1. #1
    Registered User
    Join Date
    08-26-2011
    Location
    NJ
    MS-Off Ver
    Excel 2007
    Posts
    1

    Red face formula with constraints

    I have a spreadsheet for a work schedule.
    Cell C10 - time in, eg 9:30AM
    Cell D10 - time out, eg 6:30 PM
    Cell E10 calculates the hours of 9

    I need F10 to return a number based on the following.

    If someone works more than 7 hours they need to take a one hour lunch, if they work less than 7 but more than 4 hours, they need to take a 30 minute lunch, if they work a shift that is less than 4 hours they don't get a "lunch".

    So I need F10 to return to me the hours that the employee will be paid. The value of E10 less the "lunch" time, if any.

    Any help is Greatly appreciated!!!

    Thank you,

    DevilsLvr

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: formula with constraints

    Hello & Welcome to the Board,

    This seems a little messy, but it seems to work...

    =IF(MOD(D10-C10,1)*24>7,MOD(D10-C10,1)*24-TIME(1,0,0)*24,IF(AND(MOD(D10-C10,1)*24>4,MOD(D10-C10,1)*24<7),MOD(D10-C10,1)*24-TIME(0,30,0)*24,MOD(D10-C10,1)*24))
    HTH
    Regards, Jeff

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: formula with constraints

    Hello and welcome to the forum,

    Maybe look at the attached workbook and tell me if this is what you are looking for.

    abousetta
    Attached Files Attached Files
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: formula with constraints

    Hi abousetta,

    One observation...What if they work past midnight?

    Example:
    C10 = 9:30 AM
    D10 = 6:30 AM
    Result is 21 hours

    So a minor update...instead of...

    =(D10-C10)*24 which produces -3 with the above variables

    Change to...

    =MOD(D10-C10,1)*24 which produces 21 with the above variables

    Just a thought. I know the OPs example does not cross midnight, but could be the next question.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: formula with constraints

    Hi Jeff,

    You are right... I sort of stayed away from this issue intentionally since the original example didn't show this as a possibility. But the formula should cover all the bases for it to be complete.

    abousetta

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