如果值为“已完成”,则需要找到任务完成的百分比,我需要一个宏代码来计算 D、E、F、G 列的 0 级任务中的该百分比。尽管有 COUNT 个,但如果该值已完成,我需要计算任务完成的百分比。对于 llevel 为 0 的每个任务都需要进行此计算
工作分解结构编号 | 任务描述 | 等级 | 已开发 | 已测试 | 准备发布 | 已完成(%) |
---|---|---|---|---|---|---|
1 | 电子邮件 | 0 | 11 | 11 | 11 | 11 |
1.1 | 触发派对预订确认电子邮件 | 1 | 已完成 | 已完成 | 已完成 | 已完成 |
1.2 | 触发派对预订部分付款电子邮件 | 1 | 已完成 | 已完成 | 进行中 | |
1.3 | 触发派对预订全额付款电子邮件 | 1 | 已完成 | 已完成 | 进行中 | |
1.4 | 触发派对预订取消电子邮件 | 1 | 已完成 | 已完成 | 进行中 | |
1.5 | 触发派对预订重新安排电子邮件 | 1 | 已完成 | 已完成 | 进行中 | |
1.6 | 触发活动预订确认电子邮件 | 1 | 已完成 | 已完成 | 进行中 | |
1.7 | 触发活动预订取消电子邮件 | 1 | 计划中 | 已完成 | 进行中 | |
1.8 | 触发活动预订重新安排电子邮件 | 1 | 计划中 | 已完成 | 进行中 | |
1.9 | 触发时段预订确认电子邮件 | 1 | 计划中 | 已完成 | 进行中 | |
1.10 | 触发时段预订取消电子邮件 | 1 | 计划中 | 已完成 | 进行中 | |
1.11 | 触发预订重新安排时间段电子邮件 | 1 | 计划中 | 计划中 | 计划中 | 计划中 |
2 | 网站 | 0 | 34 | 34 | 34 | 34 |
2.1 | 作为访客,我想查看豁免页面 | 1 | 计划中 | 进行中 | ||
2.2 | 作为访客,我想以访客身份注册豁免 | 1 | 计划中 | 进行中 | ||
2.3 | 作为访客,我想以客户身份注册豁免 | 1 | 计划中 | 进行中 | ||
2.4 | 作为客户,我想验证我的帐户,然后我应该能够登录 | 1 | 计划中 | 进行中 | ||
2.5 | 作为客户,我想更改密码 | 1 | 计划中 | 进行中 | ||
2.6 | 作为客户,我想使用重置密码功能恢复我的密码 | 1 | 计划中 | 进行中 | ||
2.7 | 作为客户,我想通过登录获得我的个人资料信息以豁免 | 1 | 计划中 | 进行中 | ||
2.8 | 作为客户,我想通过登录获得我的孩子信息以豁免 | 1 | 计划中 | 进行中 | ||
2.9 | 作为客户,我想查看我之前签署的弃权书 | 1 | 计划中 | 进行中 | ||
2.10 | 作为访客,我想查看联系我们页面 | 1 | 计划中 | 进行中 | ||
2.11 | 作为访客,我想向 PeekNplay 提交查询 | 1 | 计划中 | 进行中 | ||
2.12 | 作为访客,我想收到一封确认电子邮件 | 1 | 计划中 | 进行中 | ||
2.13 | 作为管理员,我希望在客户提交查询时收到确认电子邮件 | 1 | 计划中 | 进行中 | ||
2.14 | 作为访客,我想订阅时事通讯 | 1 | 计划中 | 进行中 | ||
2.15 | 作为访客,我想收到新闻通讯的确认电子邮件 | 1 | 计划中 | 进行中 | ||
2.16 | 作为管理员,我希望在客户签署电子邮件通讯时收到确认电子邮件 | 1 | 计划中 | 进行中 | ||
2.17 | 作为访客,我想看到基于 CRM 数据的派对预订页面 | 1 | 计划中 | 进行中 |
Sub CountLevel1TasksInLevel0()
Dim lastRow As Long
Dim Level0Row As Long
Dim TaskCount As Long
' Find the last row in the worksheet
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Initialize the variables
Level0Row = 0
TaskCount = 0
' Loop through the rows to count Level 1 tasks in Level 0
For i = 2 To lastRow
If Cells(i, 3).Value = 0 Then
' If Level 0 is encountered, check if there were Level 1 tasks in the previous Level 0
If Level0Row > 0 Then
' Place the count in Column D (4th column)
Cells(Level0Row, 4).Value = TaskCount
' Place the count in Column E (5th column)
Cells(Level0Row, 5).Value = TaskCount
' Place the count in Column F (6th column)
Cells(Level0Row, 6).Value = TaskCount
' Place the count in Column G (7th column)
Cells(Level0Row, 7).Value = TaskCount
TaskCount = 0 ' Reset the task count
End If
Level0Row = i ' Set the Level 0 row
ElseIf Cells(i, 3).Value = 1 Then
' If Level 1 task is encountered, increment the task count
TaskCount = TaskCount + 1
End If
Next i
' Check if there were Level 1 tasks in the last Level 0
If Level0Row > 0 Then
' Place the count in Column D (4th column)
Cells(Level0Row, 4).Value = TaskCount
' Place the count in Column E (5th column)
Cells(Level0Row, 5).Value = TaskCount
' Place the count in Column F (6th column)
Cells(Level0Row, 6).Value = TaskCount
' Place the count in Column G (7th column)
Cells(Level0Row, 7).Value = TaskCount
End If
结束子
尝试这个解决方法:
Sub CountLevel1TasksInLevel0()
Dim lastRow As Long
Dim Level0Row As Long
Dim TaskCount As Long
' Find the last row in the worksheet
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Initialize the variables
Level0Row = 0
TaskCount = 0
' Loop through the rows to count Level 1 tasks in Level 0
For i = 2 To lastRow
If Cells(i, 3).Value = 0 And Level0Row = 0 Then
' If Level 0 is encountered, check if there were Level 1 tasks in the previous Level 0
Level0Row = i
ElseIf Cells(i, 3).Value = 1 Then
' If Level 1 task is encountered, increment the task count
TaskCount = TaskCount + 1
If Cells(i, 4) = "Completed" Then col4 = col4 + 1
If Cells(i, 5) = "Completed" Then col5 = col5 + 1
If Cells(i, 6) = "Completed" Then col6 = col6 + 1
ElseIf Level0Row > 0 And Cells(i, 3) = 0 Then
' Place the count in Column D (4th column)
Cells(Level0Row, 4).Value = col4 / TaskCount
' Place the count in Column E (5th column)
Cells(Level0Row, 5).Value = col5 / TaskCount
' Place the count in Column F (6th column)
Cells(Level0Row, 6).Value = col6 / TaskCount
' Place the count in Column G (7th column)
Cells(Level0Row, 7).Value = (col4 + col5 + col6) / (TaskCount * 3)
TaskCount = 0 ' Reset the task count
Level0Row = i ' Set the Level 0 row
col4 = 0
col5 = 0
col6 = 0
End If
Next i
' Check if there were Level 1 tasks in the last Level 0
If Level0Row > 0 Then
' Place the count in Column D (4th column)
Cells(Level0Row, 4).Value = col4 / TaskCount
' Place the count in Column E (5th column)
Cells(Level0Row, 5).Value = col5 / TaskCount
' Place the count in Column F (6th column)
Cells(Level0Row, 6).Value = col6 / TaskCount
' Place the count in Column G (7th column)
Cells(Level0Row, 7).Value = (col4 + col5 + col6) / (TaskCount * 3)
End If
End Sub