如何计算Excel中两个日期截止日期之间的天数

时间:2016-01-07 21:25:06

标签: excel excel-formula

我有一个看起来像这样的Excel工作簿

Year Date   Was the office open?
2016-01-01  Y
2016-01-02  Y
2016-01-03  N
2016-01-04  N
2016-01-05  N
2016-01-06  Y
2016-01-07  Y
2016-01-08  Y
2016-01-09  Y
2016-01-10  Y
2016-01-11  N
2016-01-12  Y
2016-01-13  Y
2016-01-14  Y
2016-01-15  Y
2016-01-16  N
2016-01-17  Y
2016-01-18  Y
2016-01-19  Y
2016-01-20  Y
2016-01-21  Y
2016-01-22  Y
2016-01-23  Y
2016-01-24  Y
2016-01-25  Y
2016-01-26  Y
2016-01-27  N
2016-01-28  Y
2016-01-29  Y
2016-01-30  Y
2016-01-31  Y
2016-02-01  Y
2016-02-02  Y

我在工作簿中有第二个电子表格,看起来像这样

Period Cutoff Dates
2016-01-01
2016-01-06
2016-01-12
2016-01-16
2016-01-27
2016-02-02

我想要的是一种基于Y / N的vlookup和count,它根据日期(或第一个日期)和前一个日期的差异告诉我该期间办公室开放的天数。我想看看这个

Year Date   Was the office open?    Days office was open in the period
2016-01-01  Y   
2016-01-02  Y   
2016-01-03  N   
2016-01-04  N   
2016-01-05  N   Count the number of 'Y' between 2016-01-01 and 2016-01-06 less 1 day, show 2 in the 3rd column
2016-01-06  Y   
2016-01-07  Y   
2016-01-08  Y   
2016-01-09  Y    
2016-01-10  Y   
2016-01-11  N   Count the number of 'Y' between 2016-01-06 and 2016-01-12 less 1 day, show 5 in the 3rd column
2016-01-12  Y   
2016-01-13  Y   
2016-01-14  Y   
2016-01-15  Y   Count the number of 'Y' between 2016-01-12 and 2016-01-16 less 1 day, show 4 in the 3rd column
2016-01-16  N   
2016-01-17  Y   
2016-01-18  Y   
2016-01-19  Y   
2016-01-20  Y   
2016-01-21  Y   
2016-01-22  Y   
2016-01-23  Y   
2016-01-24  Y   
2016-01-25  Y   
2016-01-26  Y   Count the number of 'Y' between 2016-01-16 and 2016-01-27 less 1 day, show 10 in the 3rd column
2016-01-27  N   
2016-01-28  Y   
2016-01-29  Y   
2016-01-30  Y   
2016-01-31  Y   
2016-02-01  Y   
2016-02-02  Y   Count the number of 'Y' between 2016-01-27 and 2016-02-02, show 6 in the 3rd column

这应该很容易。我只是无法到达那里。任何帮助将不胜感激。

谢谢 JM

1 个答案:

答案 0 :(得分:2)

试试这个:

=IF(COUNTIF(Sheet25!$A:$A,Sheet24!A2+1),COUNTIFS($A:$A,">=" & INDEX(Sheet25!$A:$A,MATCH(Sheet24!A2,Sheet25!$A:$A)),$A:$A,"<="&INDEX(Sheet25!$A:$A,MATCH(Sheet24!A2,Sheet25!$A:$A)+1)-1,$B:$B,"Y"),"")

使用短名单将Sheet25更改为工作表名称。

放入C2并复制。

![enter image description here