我試圖確定在以下形式輸出的移位中設備的運行時間;VBA Excel Do While語句
27/01/2016 18:00:00 4
28/01/2016 6:00:00 12
28/01/2016 18:00:00 4
29/01/2016 6:00:00 0
宏旨在環向下列以及記錄開始時間和輪班結束時間即
28/01/2016 02:00 to 28/01/2016 22:00:00.
如果有一個零的塊由連續時之後。
然而,如果有時間像下面的第二4小時成爲一個單獨的塊中的差距:
27/01/2016 18:00:00 4
28/01/2016 6:00:00 12
28/01/2016 18:00:00 0
29/01/2016 6:00:00 4
我當前的代碼如下所示
Sub EX01()
Dim ColCount As Long
Dim startrow, endrow As Long
Dim i, j As Long
Dim nextRow As Long
Dim Cumm As Double
Set wb = ThisWorkbook
Set ws = wb.Sheets("XACT RE")
Set ws3 = wb.Sheets("RE_EX 01")
ws.Select
startrow = Cells(1, 2).Value
endrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row - 1
Cells(1, 28) = startrow
Cells(1, 29) = endrow
nextRow = 2 'this is the row to put info on RE sheet
For j = 3 To 6
For i = startrow To endrow
Cumm = 0
If Cells(i, j) <> 0 Then
'this is the inital pickup row
ws3.Cells(nextRow, 1) = ws.Cells(i + 1, 2) - (ws.Cells(i, j).Value/24) 'get next row time and subtract the hours in this cell
ws3.Cells(nextRow, 3) = ws.Cells(3, j)
Cumm = Cumm + ws.Cells(i, j).Value
'now check how long the run goes for and add the delay data to Cumm
Do While Cells(i + 1, j).Value >= 12
i = i + 1
Cumm = Cumm + ws.Cells(i, j).Value
Loop
'this exits loop if less than 10
ws3.Cells(nextRow, 2) = ws.Cells(i, 2).Value + ((ws.Cells(i, j).Value) * (0.5/12))
ws3.Cells(nextRow, 8) = Cumm
nextRow = nextRow + 1
End If
Next i
Next j
End Sub
所以我的問題是怎麼做的我考慮了不到12小時的單一班次,我如何解釋12小時後發生的小班(小於12)......
你的問題是什麼? – Gareth
@Gareth我編輯了它 – Maverick27