+ Reply to Thread
Results 1 to 21 of 21

CF for time difference - fixing formula

  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    CF for time difference - fixing formula

    Hi,

    I have this CF formula for highlighting cells If time difference between working shifts are less than 11 hours :

    Please Login or Register  to view this content.

    This formula is inserted in Start/End cells and kind of works for night shifts, but problem is that It only calculates difference from cells.

    So mistake is done when, example :

    - on 1st Day I select End time like "14:00", and then next day I select "15:00" in Start cell ;

    In this case It highlights cells, but It shouldn't.

    Any way to fix this ??

    Take a look at my sample, you'll understand better !!
    Attached Files Attached Files

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: CF for time difference - fixing formula

    Unmerge cells d5,d5,f5,g5 and place dates in e5 and f5 and try =AND($E$8<>""; $F$8<>"";( $F$8+$F$5-$E$8-$E$5)<11/24) as CF

  3. #3
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Hi Pepe,
    unfortunally I have a lot of VBA code for merged cells, so unmerging cells is not what I'm looking for. Have you any other ideas ?

    Thanks for help though !!

  4. #4
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    What I meant,

    any editing not desirable, just formula fix !
    Last edited by Lukael; 07-13-2014 at 11:59 AM.

  5. #5
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Unmerge cells d5,d5,f5,g5 and place dates in e5 and f5 and try =AND($E$8<>""; $F$8<>"";( $F$8+$F$5-$E$8-$E$5)<11/24) as CF
    Tried that too, but not working...

  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,936

    Re: CF for time difference - fixing formula

    I know this does not answer your question, but...
    unfortunally I have a lot of VBA code for merged cells
    You should avoid using merged cells if at all possible - they cause nothing but problems with formulas
    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

  7. #7
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    You should avoid using merged cells if at all possible - they cause nothing but problems with formulas
    I realized that some time ago, but now I'm very close to finishing everything, so I would not like to start all over again

  8. #8
    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,936

    Re: CF for time difference - fixing formula

    OK try this for the CF rule...
    =$D$5+$E8+11/24>=$F$5+$F8

  9. #9
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Quote Originally Posted by FDibbins View Post
    OK try this for the CF rule...
    =$D$5+$E8+11/24>=$F$5+$F8
    This one works, but problems with night shift. If you for example select shift from 18-06 on 1st day, you shouldn't select start time of shift next day till 17:00, otherwise CF

    You think that could be done ?

  10. #10
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    What about combining both formulas ? I was thinking - If D8 is more than 12:00 (all night jobs starts with more than 12:00) then first CF formula, otherwise second one.

    Tried this but not working :

    Please Login or Register  to view this content.

    anybody have an idea how to combine them correctly ??

  11. #11
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    I almost solved this formula.

    Only thing left to include is to highlight both cells in case like this, example :

    - If first day shift is 18-06, and second day shift is 07-19.


    my current formula is :

    =IF($D$8<TIMEVALUE("12:00");$D$5+$E8+10/24>=$F$5+$F8;IF($D$8>TIMEVALUE("12:00");AND($E8<>""; $F8<>""; 10/24>=IF($E8>$F8;1;0)+$F8-$E8;10/24>=IF($E8<=$F8;1;0)+$F8-$E8);0))

    Anybody have any suggestions ?

  12. #12
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: CF for time difference - fixing formula

    Does this modification of FDibbins formula work?

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    No, this doesn't work. Thanks for trying

  14. #14
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: CF for time difference - fixing formula

    I think it may work if you include the dates in the calculation.

    My conditional formatting formula:
    Please Login or Register  to view this content.
    Lewis
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Hi LJMetzger,

    tried this but still not working. Just as in mine formula, only one combination not working - for night shifts

    If you select lets say 18:00 in D8 and 03:00 in E8 - that's night shift..... So in F8 any time that is less than 14:00 should CF both cells (E8 & F8).


    I created formula for only that combination, but cannot combine It with other parts. I tried with nested IF, OR, AND - so far no success. But I'm sure this is possible

    Formula for that combination :

    Please Login or Register  to view this content.
    or just

    10/24>=F8-E8
    Maybe you can combine this your formula ?

  16. #16
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Ok, I'm really getting and headache now...

    I think (but not sure), that this formula might work :

    =IF(AND(D8>TIMEVALUE("12:00");E8>TIMEVALUE("12:00");$D$5+$E8+10/24>=$F$5+$F8);1;IF(IF(AND(D8>TIMEVALUE("12:00");E8<TIMEVALUE("12:00"));10/24>=F8-E8;0);1;IF(D8<TIMEVALUE("12:00");AND($E8<>"";$F8<>"";10>=24*($F$5+$F$8-$D$5-$E$8));AND(D8>TIMEVALUE("12:00");E8<TIMEVALUE("12:00");10/24>=F8-E8))))
    Yes, It's a long formula, I know. Hard to explain It, but I tried to nest all combinations with IF function - I went step to step till I ended this far. In some cases formula shows True or False, and in some cases 1 or 0, in correct results.

    Problem ? Yes. This formula can't be pasted in CF.

    Why ? Is It too long ??

    Maybe someone could try to paste It ?
    Last edited by Lukael; 07-26-2014 at 01:18 PM.

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

    Re: CF for time difference - fixing formula

    Quote Originally Posted by Lukael View Post
    This formula can't be pasted in CF.

    Why ? Is It too long ??
    Yes, it's too long.

    CF formulas can not be more than 255 characters long.

    Your formula is 292 characters.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  18. #18
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: CF for time difference - fixing formula

    Lukael, you can change all those
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    into number
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Hey Zbor,

    That should do It

    I'm not at home right now, so I can't test It, but I think everything is going to be just fine. I'll let you all know tomorrow

    If someone has maybe another "easier" solution, please post It, I think this "between" time interval calculation is something to discuss about !

  20. #20
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: CF for time difference - fixing formula

    Have tested It today, It works just fine !!

    This is now final working formula :

    Please Login or Register  to view this content.
    Thank you all for your help, specially to FDibbins & zbor !!
    Last edited by Lukael; 07-27-2014 at 12:53 PM.

  21. #21
    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,936

    Re: CF for time difference - fixing formula

    Im really happy you finally got what you needed here, and thanks for the feedback

+ 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. [SOLVED] time difference formula - need fix
    By Lukael in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-21-2014, 12:58 AM
  2. [SOLVED] Formula for time difference
    By MyOnion in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-19-2013, 03:13 AM
  3. Time difference formula help
    By gcwozniak in forum Excel General
    Replies: 2
    Last Post: 05-24-2011, 10:08 PM
  4. [SOLVED] Need formula to calculate time difference
    By markndawoods in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-13-2006, 11:25 AM
  5. Time Difference Formula
    By MEL79 in forum Excel General
    Replies: 2
    Last Post: 03-11-2005, 05:57 PM

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