2017-10-12 70 views
0

我在Excel中有一个TODO列表,其中所有任务都被分类并具有唯一的ID(1.1,1.2,2.1等)。有些任务需要完成一个或多个其他任务(即只有当1.1,1.2,1.3和2.5完成时才能启动1.4)。用户可以添加他自己的标准,以确定哪些任务必须完成。这可以是任何任务的组合。当一个单元格中提到的所有任务都完成时Excel条件格式

表信息: Column A - ID(1.1; 1.2; 2.1; 2.2)

Column H - 状态(其中 “V” 表示检查的符号,这意味着它是完成)

Column K - 预条件(用户输入如“3.1,2.1,4.5”作为一个文本值)

我想测试单元中的每个ID在细胞中完成。

有没有人知道一个很好的方法来做到这一点?

该图显示了任务列表的摘要。您看到第5行(ID 1.2)K栏中的单元格为绿色,因为所述ID已完成。列27(ID 3.2)应显示绿色值当两个任务2.3和3.1都完成(又名具有在列H.一个“V”的先决条件的量可以每个任务而变化。

Image of desired result

+0

您能否包含实际电子表格的屏幕截图和期望的结果示例? – ImaginaryHuman072889

回答

0

当作为列条件格式K.

=countifs($A$1:$A$1000,$K1,$H$1:$H$1000,"v")>0

检查与多个任务的单元格中输入的第一部分非常简单,如下公式将为K5,K6,K15和工作更加困难,你可能需要将它们分成隐藏列中的单元格以检查它们。

您可以使用自定义VBA函数检查具有多个任务的单元。功能添加到一个VBA模块并保存,然后在列中使用公式=canStart(K1)=True在条件格式K.

这将检查无限的子任务,但不会自动更新,所以你需要使用按Ctrl + Alt键+F9定期更新。

Function canStart(Rng As Range) As Variant 
Dim arrSubtasks As Variant 
Dim subTasksComplete As Boolean 

If Rng.Value <> "" Then 'check if there is a subtask in the cell 
    If InStr(1, Rng.Value, ",") > 0 Then ' check if there is more than 1 subtask (look for a comma) 
     arrSubtasks = Split(Rng.Value, ",") ' create an array of all the subtasks in the cell 
     subTasksComplete = True ' set sub tasks as complete 
     For Each subTask In arrSubtasks ' loop through each subtask 
      If Application.WorksheetFunction.CountIfs(Range("A2:A1000"), subTask, Range("K2:K1000"), "v") = 0 Then 'if the subtask being checked is not found as complete 
       subTasksComplete = False ' mark subTasksComplete as false and do not continue to check the others (save some time) 
       Exit For 
      End If 
     Next 
    Else ' if there is only one subtask then check if it's complete 
     subTasksComplete = True 
     If Application.WorksheetFunction.CountIfs(Range("A2:A1000"), Rng.Value, Range("K2:K1000"), "v") = 0 Then 
      subTasksComplete = False 
     End If 
    End If 
     canStart = subTasksComplete 'set the returned value to the value of subtasksComplete 
End If 
End Function 
相关问题