0

Hey hoping someone can help me out, first time posting but I am stuck trying to write a formula in excel to record breaks and the week in which they occurred. Basically I have a list of week ending dates, from time to time a break (or breaks) may occur, what I want is to be able to record the break range (say 8/11/2014-22/11/2014) and have the formula provide a value next to each week that was effected by that break showing how many days in that period were affected.

EG.

WEEK|WEEKEND|BREAK

week 1 10/08/2014 ?

week 2 17/08/2014 ?

week 3 11/08/2014 ?

week 4 18/08/2014 ?

BREAKS

Break 1 11/08/2014-13/08/2014

Break 2 17/08/2014-18/08/2014

Hope that makes sense, I have tried to write it as an IF formula however keep going cross eyed trying to get the ranges right and having it not count above the 7 days in that week. Think I may be approaching it entirely the wrong way.

Thanks in advance!

1 Answer 1

0

Try the following. It will not scale -- if you have a lot of breaks a VBA macro may be the way to go (it might also be possible with arrays, but I suspect it would be painful).

The formula in D2 should be as for C2, except with references to row 11 replaced by references to row 12. In E2, you would use row 13, etc. Having put formulas in C2->Y2 (or however many you need) you should be able to copy row 2 down.

   A      | B       | C                       | D          | ... | Z
1  WEEK   | WEEKEND | BREAK1                  | BREAK2     | ... | DAYS OUT
2  week 1 | 10/8/14 | = if(and($b$11>($b2-7), | = if(and...| ... | =sum(c2:y2)
                               $b$11<=$b2),
                           if($b2<$c$11,$b2-$b$11+1,$c$11-$b$11+1), 
                           if(and($b2-$c$11<7,$b2>=$c$11),$c$11-($b2-6)+1,0))

3  week 2 | 17/8/14 | = if(and($b$11>($b3-7),
                           ...
4 ...
....
10 BREAK  | START   | END
11 Break 1| 11/8/14 | 13/8/14
12 Break 2| 17/8/14 | 18/8/14
13 ...

The formula in C2:

  1. Checks to see if the break starts in the week ending on the weekend
  2. If it does, it checks to see if it ends in the week as well. If so, the days out are just the days in the break (break end - break start + 1). If not so, the days out are the days from the start of the break to the weekend (weekend - break start + 1)
  3. If the break does not start in the week ending on the weekend, check to see if the break ends in the week. If so, the days out are (break end - week start + 1). Otherwise, there are no days out.
2
  • Thanks Tony, I may have copied it incorrectly but the exact formula I have used is: =IF(AND($C$38>(D7-7),$C$38<=D7),IF(D7<$D$38,D7-$C$38+1,$D$38-$C$38+1),IF(AND(D7-$D$38<7,D7>=$D$38),$D$38-(D7-6+1),0)) Where D7 is the week end date, C38 is the break start date and D38 is the break end date. I have only just started looking but so far it returns an incorrect result, thought I would check if you could see where I was going wrong. Thanks again for the help Nov 8, 2014 at 7:50
  • The (d7-6+1) right near the end should be (d7-6) + 1. See if that fixes it.
    – Tony
    Nov 8, 2014 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.