【发布时间】:2016-04-18 01:48:10
【问题描述】:
我正在尝试确定设备在一个班次中的运行时间,它以以下形式输出;
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 我已经编辑过了
标签: excel vba if-statement for-loop do-while