下面的宏用于将员工项目日期与填充在多个列中的天数进行比较,并计算员工在特定日期工作的当前任务数量。
例如:- 如果 RANge Q3:Au3 填充了 2013 年 10 月的日期,例如 q3:1st oct、r3:2nd oct、s3:3rd oct 等等。我的代码将这些个人日期与工作表 temp calc 中的员工开始和结束日期进行比较,并通过计算员工 ID 返回员工正在处理的任务数。代码工作正常,但执行需要很长时间(因为大约有 50,000 名员工),然后在我首先将数据放入工作表后应用过滤器以删除冗余数据,例如撤回、非活动和其他员工。还有另一个过滤以删除不属于我的比较范围但员工仍然很大并且执行时间也很长的员工。
如果我无法提供足够的详细信息,我已在下面的链接中附加了我的文件,请查看。
https://docs.google.com/file/d/0B2CrBtuXvhrJSkgwbFZEWHYycTg/edit?usp=sharing
Option Explicit
Sub Count()
' x= no of columns(dashboard calender)
' y= no of rows(dashboard emp id)
' z= no of rows(temp calc sheet emp id)
Application.ScreenUpdating = False
'Clear calender data
Range("Q4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
Dim i, j, k, l, d, x, y, z, Empid As Long
Dim currentdate, startdate, enddate As Date
x = (Range("n2") - Range("n1")) + 1
y = Application.WorksheetFunction.counta(Range("A:A")) - 1
z = Application.WorksheetFunction.counta(Worksheets("Temp Calc").Range("A:A")) - 1
For i = 1 To y Step 1 'To loop through the emp_id in dashboard.
For j = 1 To x Step 1 'To loop through the calender in dashboard daywise.
d = 0
For k = 1 To z Step 1 'To loop through the emp_id i temp calc sheet.
Empid = ActiveSheet.Cells(i + 3, 1).Value
currentdate = Cells(3, 16 + j).Value
startdate = Worksheets("Temp calc").Cells(k + 1, 3).Value
enddate = Worksheets("Temp calc").Cells(k + 1, 4).Value
If (Worksheets("Temp calc").Cells(k + 1, 1).Value) = Empid Then
If (currentdate >= startdate) And (currentdate <= enddate) Then 'To check whether the first column date falls within the project start and end date
d = d + 1
End If
End If
Next
Worksheets("Dashboard").Cells(i + 3, j + 16) = d
Next
Next
Range("q4").Select
Application.ScreenUpdating = True
End Sub