简体   繁体   English

Excel COUNTIFS:尝试计算未完成任务的拖欠日期

[英]Excel COUNTIFS: Trying to count delinquent dates for tasks that have not been completed

I am trying to count the number of open tasks where the 'Plan' date is before 'Today's date', but does not have an 'Actual Completion Date'. 我正在尝试计算“计划”日期早于“今天的日期”,但没有“实际完成日期”的未完成任务的数量。 Here is an example of the data I am working with (columns are separated by a comma): 这是我正在使用的数据的示例(列用逗号分隔):

Today's Date, 07/23/2013

Item 1, Plan Date, 07/01/2013
Item 1, Expected Completion Date, 08/02/2013
Item 1, Actual Completion Date,
Item 2, Plan Date, 07/01/2013
Item 2, Expected Completion Date, 08/02/2013
Item 2, Actual Completion Date, 12/01/2013
Item 3, Plan Date, 08/23/2013
Item 3, Expected Completion Date, 08/23/2013
Item 3, Actual Completion Date,

I tried using the 'COUNTIFS' function within excel to count items that do not have an 'Actual Completion Date', but have a 'Plan Date' prior to 'Today's date' (07/23/2013). 我尝试在excel中使用“ COUNTIFS”功能对没有“实际完成日期”但在“今天的日期”之前存在“计划日期”的项目进行计数(2013年7月23日)。 In the example data above, I would expect the calculation to return '1' (since only Item 1 satisfies this criteria). 在上面的示例数据中,我希望计算返回“ 1”(因为只有第1项满足此条件)。 However, I have not been successful in creating a 'COUNTIFS' function that would work. 但是,我没有成功创建可以起作用的“ COUNTIFS”功能。

Can anyone help? 有人可以帮忙吗? I am trying using VBA to solve this problem. 我正在尝试使用VBA解决此问题。

Here is an example of a 'COUNTIFs' function I tried but did not work (returned '0'): 这是我尝试但无法使用的“ COUNTIFs”函数的示例(返回“ 0”):

=COUNTIFS(B4:B12,"Actual Completion Date",C4:C12,"",B4:B12,"Plan Date",C4:C12,"<"&$C$2)

Column 'B' is for 'Plan Date', 'Expected Completion Date', and 'Actual Completion Date'.
Column 'C' is for dates corresponding to 'Plan Date', 'Expected Completion Date', and 'Actual Completion Date'.
Cell C2 is 'Today's Date' (07/23/2013).

No VBA is required, you can use the SUMPRODUCT formula. 不需要VBA,可以使用SUMPRODUCT公式。

=SUMPRODUCT(--($A$3:$A$11=A17),--($B$3:$B$11=" Plan Date"),--($C$3:$C$11<$B$1))*SUMPRODUCT(--($A$3:$A$11=A17),--($B$3:$B$11=" Actual Completion Date"),--($C$3:$C$11<1))

I copied your csv and pasted into a new sheet starting at cell A1. 我复制了您的csv,然后粘贴到了从单元格A1开始的新工作表中。 In cells A17-19 I have "Item 1", "Item 2", and "Item 3" respectively, and My formula is in cells B17-19. 在单元格A17-19中,我分别具有“项目1”,“项目2”和“项目3”,而我的公式位于单元格B17-19中。

There's actually two instances of SUMPRODUCT in this formula. 此公式中实际上有两个SUMPRODUCT实例。

The first checks for rows that contain "Item 1" AND " Plan Date" AND that the date is less than Today's Date in cell B1. 第一个检查包含“ Item 1”和“ Plan Date”并且日期小于单元格B1中“今天的日期”的行。 Since all criteria are met I get a TRUE value of 1. 由于满足所有条件,因此我得到的TRUE值为1。

The second instance looks for the item AND "Actual Completion Date" AND that there is no date (date<1) in the date column. 第二个实例查找与“实际完成日期”相符的项目,并且在日期列中没有日期(date <1)。 Since all criteria are met I get a TRUE value of 1. 由于满足所有条件,因此我得到的TRUE值为1。

I then multiply the two results 1*1=1. 然后,我将两个结果相乘1 * 1 = 1。

I then copy the formula down so it checks items 2 and 3. Item 2 returns a 0 because the second condition fails (there IS a completion date) and item 3 fails because the first condition fails (the start date is later than today's date) 然后,我将公式复制下来,以便检查项目2和3。项目2返回0,因为第二个条件失败(有完成日期),项目3失败,因为第一个条件失败(开始日期晚于今天的日期)

Countifs returns a value if all the conditions are true. 如果所有条件都为真,则Countifs返回一个值。 In your countifs B4:B12,"Actual Completion Date" and B4:B12,"Plan Date" can't be true in the same time and that is the problem why you get 0. 在您的计数B4:B12中,“实际完成日期”和B4:B12中,“计划日期”不能同时为真,这就是为什么您获得0的问题。

In vba you could try this basic code supposing that you always have 3 lines, the order of the 3 dates is the same and you start from the 4th row. 在vba中,您可以尝试以下基本代码,假设您始终有3行,这3个日期的顺序是相同的,并且您从第4行开始。

Sub check()
Dim rng As Range, cell As Range, n As Integer, m As Integer, cont As Integer
Set rng = Range("B4:B12")
n = 0
m = 1
For Each cell In rng
    n = n + 1
    If (n = 3 * m) Then
    m = m + 1
         If (Range("D" & 3 + n).Value = "") Then
            If (Range("D" & 3 + n - 2).Value >= "&C2") Then
                cont = cont + 1
            End If
        End If
    End If
Next cell
Debug.Print (cont)

End Sub 结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM