'************************************************

'定数定義達
'
'************************************************

 

 

Public Enum SchMainRow
Number = 2
Module = 3
Modtype = 4
Taskno = 5
Patask = 6
Taskname = 7
Tantoname = 9
TantoID = 10
time = 11
Startday = 12
Endday = 13
Progress = 15
Delay = 16
Status = 17
Remarks = 18
shestartdate = 19
End Enum

Dim TantoID
Dim worktime
Dim workno
Dim startdate
Dim startcol
Dim temptime
Dim time
Dim color
Dim flg
'計画作成
Sub aaa()
Sheets("スケジュール").Select
dataclear


'最終行を取得する。
MaxRow = Range("B65536").End(xlUp).Row

y = 7
Do Until y = MaxRow + 2
maketask (y)
y = y + 2

Continue:
Loop

End Sub
'実績作成
Sub bbb()
Sheets("スケジュール").Select
'最終行を取得する。
MaxRow = Range("B65536").End(xlUp).Row
y = 8
Do Until y = MaxRow + 1
makezisseki (y)
y = y + 2
Continue:
Loop

End Sub

Sub maketask(line As Integer)
'まず、いつスタートか確認する。
'そいつはだれ?
TantoID = Cells(line, SchMainRow.TantoID).Value
worktime = Application.WorksheetFunction.VLookup(TantoID, Sheets("パラメータシート").Range("A:C"), 3, False)
workno = Application.WorksheetFunction.VLookup(TantoID, Sheets("パラメータシート").Range("A:D"), 4, False)
color = Sheets("パラメータシート").Range("A1").CurrentRegion.Find(What:=TantoID).Interior.color

'開始日付が赤かった場合は、それが最新開始日数とする。
'日付が赤くない場合は、最短日程を入れる。
If Cells(line, SchMainRow.Startday).Font.ColorIndex = 3 Then
startdate = Cells(line, SchMainRow.Startday).Value
startcol = SchMainRow.shestartdate + DateDiff("d", Cells(5, SchMainRow.shestartdate).Value, startdate)
Else
startdate = Cells(5, SchMainRow.shestartdate).Value
startcol = SchMainRow.shestartdate
End If

'そのタスクの時間を設定する。
worktime2 = Cells(line, SchMainRow.time).Value

x = 0
flg = False
Do Until worktime2 <= 0
'その日が休み(赤文字)だった場合はループを抜ける
If Cells(5, startcol + x).Font.ColorIndex = 3 Then
GoTo Continue
End If

'まずは予定工数シートの部分に着目する。
'そのときに、そのメンバーの工数はその日何時間残っているかを確認する。
time = worktime - Sheets("予定工数").Cells(workno + 2, startcol + x).Value
'その日に作業できなければ、次の日へ
If time <= 0 Then
GoTo Continue
End If
'その日に何時間使うか
If worktime2 - time > 0 Then
Sheets("予定工数").Cells(workno + 2, startcol + x).Value = Sheets("予定工数").Cells(workno + 2, startcol + x).Value + time
Cells(line, startcol + x).Value = time
Cells(line, startcol + x).Interior.color = color
worktime2 = worktime2 - time
Else
Sheets("予定工数").Cells(workno + 2, startcol + x).Value = Sheets("予定工数").Cells(workno + 2, startcol + x).Value + worktime2
Cells(line, startcol + x).Value = worktime2
Cells(line, startcol + x).Interior.color = color
worktime2 = 0
End If
'開始日付を入力
If startflg = False And Cells(line, SchMainRow.Startday).Font.ColorIndex <> 3 Then
startflg = True
Cells(line, SchMainRow.Startday).Value = Cells(5, SchMainRow.shestartdate + x).Value
End If
'終了日付を入力
If worktime2 <= 0 And Cells(line, SchMainRow.Endday).Font.ColorIndex <> 3 Then
Cells(line, SchMainRow.Endday).Value = Cells(5, SchMainRow.shestartdate + x).Value
End If


Continue:
x = x + 1
Loop

End Sub
Sub makezisseki(line As Integer)

startcol = SchMainRow.shestartdate + DateDiff("d", Cells(2, 5).Value, Cells(3, 5).Value)
Do Until startcol - SchMainRow.shestartdate = 0
Cells(line, SchMainRow.time).Value = Cells(line, SchMainRow.time).Value + Cells(line, startcol).Value

Continue:
startcol = startcol - 1
Loop

End Sub

Sub dataclear()
'過去データをすべてクリアする。
Range("S7:" & ActiveSheet.Cells.SpecialCells(xlLastCell).Address).ClearContents
Range("S7:" & ActiveSheet.Cells.SpecialCells(xlLastCell).Address).Interior.ColorIndex = 2
Sheets("予定工数").Range("S3:" & Sheets("予定工数").Cells.SpecialCells(xlLastCell).Address).ClearContents
End Sub