이전 시프트 데이터를 표시하는 프로그램을 만듭니다. 시프트 1 : 오전 6시에서 오후 2 시까 지 3 시프트가 있습니다. 시프트 2 : 오후 2시에서 오후 10 시까 지 Shift 3시 10 분부터 6 시까 지 현재 시간에 따라 이전 1 시프트에서 모든 데이터를 복사 할 수 있어야합니다.VBA의 논리로 고민 : 날짜 및 시간 포함
저는 지난 주 동안 내 뇌를 망가 뜨 렸습니다. 지금까지는 아무런 운이 없었습니다. 프로그램은 잘 돌아 갔지만 논리는 올바르지 않습니다. 나는 이전 데이터베이스에 속하지 않는 다른 데이터도 얻고있다.
다음은 논리 만 포함 된 추출입니다. 이 문제에 도움을 주실 수 있습니까? 당신이 그것을 기대하는 것처럼
For i = lastrow1 To (lastrow1 - 150) Step -1
mydate = Sheets("Summary").Cells(i, "A").Value
mytime = Sheets("Summary").Cells(i, "B").Value
mystatus = Sheets("Summary").Cells(i, "J").Value
Sheets("Previousshiftdata").Activate
lastrow2 = Sheets("Previousshiftdata").Range("A" & Rows.Count).End(xlUp).Row
'j indicates destination row no i.e. row no. in previoushift
j = lastrow2 + 1
'to get shift 3 data
If (x = "Shift 3" And (mydate = Date - 1 And mytime > TimeValue("22:00:00"))) Or (mydate = Date And mytime > TimeValue("00:00:00") And mytime < TimeValue("6:00:00")) Then
Sheets("Summary").Activate
Sheets("Summary").Range(Cells(i, "A"), Cells(i, "J")).Copy
Sheets("Previousshiftdata").Activate
Sheets("Previousshiftdata").Range(Cells(j, "A"), Cells(j, "J")).Select
Selection.PasteSpecial Paste:=xlPasteValues
'to get shift 2 data
ElseIf ((mydate = Date) And (mytime > TimeValue("14:00:00")) And (mytime < TimeValue("22:00:00"))) Or ((mydate = Date - 1) And (mytime > TimeValue("14:00:00")) And (mytime < TimeValue("22:00:00"))) Then
Sheets("Summary").Activate
Sheets("Summary").Range(Cells(i, "A"), Cells(i, "J")).Copy
Sheets("Previousshiftdata").Activate
Sheets("Previousshiftdata").Range(Cells(j, "A"), Cells(j, "J")).Select
Selection.PasteSpecial Paste:=xlPasteValues
'to get shift 1 data
ElseIf (TimeValue("6:00:00") < mytime < TimeValue("14:00:00")) And (mydate = Date) Then
Sheets("Summary").Activate
Sheets("Summary").Range(Cells(i, "A"), Cells(i, "J")).Copy
Sheets("Previousshiftdata").Activate
Sheets("Previousshiftdata").Range(Cells(j, "A"), Cells(j, "J")).Select
Selection.PasteSpecial Paste:=xlPasteValues
End If
'to clear clipboard
Application.CutCopyMode = False
Next i
Sheets("Previousstatus").Activate
End Sub
'TimeValue ("6:00:00")
JohnyL
'IF'블록 내부에는 차별화가 없습니다. 1) 모든 결과가 똑같은 경우 'IF'블록을 갖는 점은 무엇입니까? 2) 같은 코드를 3 번 쓰는 이유는 무엇입니까? 프로 시저가 필요할 때 실행하고 호출하기 위해 호출 할 수있는 루틴을 작성하십시오. –