jag108
Active Member
- Joined
- May 14, 2002
- Messages
- 433
- Office Version
-
- 365
- 2016
- Platform
-
- Windows
- MacOS
Hi,
I am trying to calculate the start time + duration to get next start time.
I have two columns column B has the start time, column "C" has the duration, I would like these to be added together to come up with the next start time.
This is a cross reference sheet to make sure that the data being imported is correct.
One thing I need to add is we work on a clock of 06:00 to 29:59 so a 30 hour clock, this is a broadcasting thing so don't get me started
My code looks like this.
Sub check_import()
Dim i As Integer, start_time, next_start_time, total_time As Date
On Error GoTo errortrap
vbyes_no = MsgBox("Please select the sheet you wish to run this code on. " & Chr(13) & _
"Is the correct sheet selected [Y/N]", vbInformation + vbYesNo, "Select the correct sheet.")
If vbyes_no = vbNo Then End
Set TestRange = Intersect(Range("E:E"), ActiveSheet.UsedRange)
lastrow = TestRange.Cells(TestRange.Cells.Count).Row 'get last row number in the range
firstrow = TestRange.Cells(1).Row 'get the first row number in the range
For i = 2 To lastrow Step 1
start_time = Cells(i, 2).Value
next_start_time = Cells(i + 1, 2).Value
duration = Cells(i, 3).Value
total_time = start_time + duration
If Not total_time = next_start_time Then
MsgBox "Cell " & Cells(i, 2).Address & " has the wrong duration."
End If
Next i
Exit Sub
errortrap:
MsgBox "An error has occured stopping this process form completing." & Chr(13) & _
"Error number: " & Err.Number & Chr(13) & "Error Description: " & Err.Description, vbExclamation + vbOKOnly, "An error has occured!"
End Sub
Any help really appreciated
I am trying to calculate the start time + duration to get next start time.
I have two columns column B has the start time, column "C" has the duration, I would like these to be added together to come up with the next start time.
This is a cross reference sheet to make sure that the data being imported is correct.
One thing I need to add is we work on a clock of 06:00 to 29:59 so a 30 hour clock, this is a broadcasting thing so don't get me started
My code looks like this.
Sub check_import()
Dim i As Integer, start_time, next_start_time, total_time As Date
On Error GoTo errortrap
vbyes_no = MsgBox("Please select the sheet you wish to run this code on. " & Chr(13) & _
"Is the correct sheet selected [Y/N]", vbInformation + vbYesNo, "Select the correct sheet.")
If vbyes_no = vbNo Then End
Set TestRange = Intersect(Range("E:E"), ActiveSheet.UsedRange)
lastrow = TestRange.Cells(TestRange.Cells.Count).Row 'get last row number in the range
firstrow = TestRange.Cells(1).Row 'get the first row number in the range
For i = 2 To lastrow Step 1
start_time = Cells(i, 2).Value
next_start_time = Cells(i + 1, 2).Value
duration = Cells(i, 3).Value
total_time = start_time + duration
If Not total_time = next_start_time Then
MsgBox "Cell " & Cells(i, 2).Address & " has the wrong duration."
End If
Next i
Exit Sub
errortrap:
MsgBox "An error has occured stopping this process form completing." & Chr(13) & _
"Error number: " & Err.Number & Chr(13) & "Error Description: " & Err.Description, vbExclamation + vbOKOnly, "An error has occured!"
End Sub
Any help really appreciated