我想實現減少返回計數
我有兩片循環執行時間:「儀表盤」和「臨時計算」。
儀表板包含所有員工詳細信息和範圍「N1」「N2」包含日期。
現在一個宏填充員工數據並生成如下圖所示的日曆日曆 'temp calc'的項目詳細信息包含開始日期結束日期(日期不在n1和n2日期之間)表格在這裏被刪除)。
因此,現在通過儀表板表引用他們的empid,並使用第一天填充在儀表板表中,我通過temp計算表中的emp id循環並返回一個員工當前正在爲特定天。如下圖所示。
我如何做到這一點:
代碼.....
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
我的問題:的代碼做這項工作,但我有兩個問題。
實在是太慢了
有時,工作簿會說沒有響應,並不會做work.I've檢查它不會在後臺工作。我讓程序在一夜之間運行,並且沒有響應。
可能的解決方案:
使用兩個陣列:一個陣列到EMPID存儲在儀表盤,儀表板中產生的第二陣列來存儲日曆。然後將它與溫度計算表中的數據進行比較,並將計數返回到數組編號2並將其寫回 問題是我剛開始閱讀有關數組,我仍在學習
我對可能的替代方法開放:
歡呼聲,
馬修
IM將改變我的計數功能,感謝弗洛里斯 關於數據透視表我想保存我的數據,因爲我的工作簿看起來有很多數據列旁邊我的員工,我需要參考 我已經在員工上排序它,但是因爲您的方法表明生病找出一些方法去到下一個員工,這將減少我的循環執行時間 虐待自動篩選方法 感謝您的建議 – mathew
在旁邊說明你仍然可以截圖和你的通知。因爲我不能,只想確認該網站是否有問題或只是我:| – mathew
不知道我理解你最後的評論?我可以看到你的截圖,並收到通知,如果這是你問的。 – Floris