Hello Forum,
My code below works great, however I have multiple unique PIDLabel groups in column D, separated with/by an empty row,
however my current macro stops in the first grouping.
Can some one please help me, so it can provide me the cycle time for each of the groups in column D?
Thank you
My code below works great, however I have multiple unique PIDLabel groups in column D, separated with/by an empty row,
however my current macro stops in the first grouping.
Can some one please help me, so it can provide me the cycle time for each of the groups in column D?
Thank you
VBA Code:
Sub MCycleTime()
Dim LastRow As Long
Dim i As Long
Dim StartTime As Date
Dim EndTime As Date
Dim FoundFirst030 As Boolean
Dim OutputRow As Long
' Find the last row with data in column E
LastRow = Cells(Rows.Count, "E").End(xlUp).Row
' Initialize vari030les
FoundFirst030 = False
' Loop through the rows
For i = 2 To LastRow ' Assuming row 1 contains headers
' Check if the event code is 030
If Cells(i, "E").Value = "030" Then
StartTime = Cells(i, "N").Value
FoundFirst030 = True
End If
' Check if the event code is 100 and we've already found the first 030
If Cells(i, "E").Value = "100" And FoundFirst030 Then
EndTime = Cells(i, "N").Value
OutputRow = i
End If
Next i
' Calculate and display the cycle time
If FoundFirst030 And EndTime > 0 Then
Cells(OutputRow, "O").Value = Format(EndTime - StartTime, "hh:mm:ss")
Else
MsgBox "Cycle time measurement could not be completed."
End If
End Sub