我正在尝试创建一个子或函数,它将输出完成/不迟的子作业的百分比。此列表使用复制和粘贴添加项目,“类别”由用户输入,“categorysub”使用= concatentate(category +“sub”)。顶部的日期是= now()函数。我正在添加使用宏添加更多“subs”的功能。添加项目按钮只需复制并粘贴第二项的范围。
我希望sub / fun to:
1)计算给定类别项目的总“子”数(不是每个工作簿中只有一个“问题”块。如红框所示)
2)按时间计算给定类别项目/编号的已完成“潜艇”的数量(未超过截止当前日期的截止日期)
3)输出已完成/开启时间的数量超过总子项
这是我到目前为止的代码:
Public Function Complt(category As String)
Dim loc As Range
loc = Application.Caller
Dim categoryCell As Range
categoryCell = Cell(loc.row, "C")
Dim categorySub As String
categorySub = category + "sub"
Dim subcat As Range
subcat = Cell(categoryCell.row - 1, "C")
Dim assignedDateCell As Range
Dim complCount As Integer
complCount = 0
Dim ActComplDate As Range
Dim numberofsubs As Integer
numberofsubs = 0
Do While subcat.Text = categorySub
numberofsubs = numberofsubs + 1
assigendDateCell = Cell("G", subcat.row)
ActComplDate = Cell("H", subcat.row)
If assignedDateCell.Value <= Sheet2.Cells(1, "G") Or IsEmpty(ActComplDate) = False Then
complCount = complCount + 1
subcat = Cell(categoryCell.row - 1, "C")
Else
complCount = complCount + 0
subcat = Cell(categoryCell.row - 1, "C")
End If
Loop
Complt = complCount / numberofsubs
End Function
答案 0 :(得分:1)
添加帮助列时,可以使用工作表公式轻松完成此操作。
在帮助栏中检查完成日期是在截止日期之前还是在截止日期:
=IF(H7<=G7,1,0)
例如在K7中
然后将此公式放在J6中以检查以下十行(如果它们包含Yieldsub),以及它们是否按时交付。
=SumIf(R[1]K[-8]:R[10]K[-8],RK[-8]&"sub",R[1]K[1]:R[10]K[1])