私が達成しようとしていること
「ダッシュボード」と「一時計算」の 2 つのシートがあります。
ダッシュボードにはすべての従業員の詳細があり、範囲「N1」「N2」には日付が含まれています。
次の画像に示すように、マクロは従業員データを取り込み、日単位のカレンダーを生成します
。「temp calc」には、開始日と終了日を含むプロジェクトの詳細があります (ダッシュボード シートの n1 と n2 の日付の間に収まらない日付はここで削除されます)。 .
そのため、ダッシュボード シートから empid を参照し、ダッシュボード シートに入力された最初の日を使用して、temp calc シートの 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
私の問題:コードは機能しますが、2 つの問題があります。
遅すぎる
ワークブックが応答しないと表示され、作業が行われないことがあります。バックグラウンドで動作しないことを確認しました。プログラムを一晩実行したままにしておくと、応答しなくなりました。
考えられる解決策:
2 つの配列を使用します。1 つの配列は empid をダッシュボードに格納し、2 つ目の配列はダッシュボードで生成されたカレンダーを格納します。次に、一時計算シートのデータと比較し、配列番号2にカウントを返し、それを書き戻します。問題は、配列について読み始めたばかりで、まだ学習中です。
私は可能な代替案を受け入れています:
乾杯、
マシュー