Time calculations, with a twist.

jag108

Active Member
Joined
May 14, 2002
Messages
433
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. 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
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi jag108:

Following is a formula based solution ... Let me know if I have understood you correctly ...
Book1
ABCDE
1
2StartTimeDurationNextStartTime
36:0023:5929:59
415:0023:598:59
522:004:3526:35
66:0023:5929:59
7
Sheet6


formula in cell D3 is ... =MOD(B3+C3,"30:00"+0)

this is then copied down!
 
Upvote 0
You have understood exactly the thing I am trying to do.

When I tried using your formula I get an error.

"You've entered to few arguments for this function."

This is what I have entered
=mod(B2+C2), "30:00" +0)
I am using Excel 2003, if that makes a difference.

But ultimately I would like this done by VBA some way.
 
Upvote 0
Hi
I think you have an extra closing bracket in your formula. Have a look at your formula compared to that from Yogi Anand.
Andrew :)
 
Upvote 0
Well spotted, cheers andrew93.

That works, but I still would really really like this done with VBA, I do not have the spare columns to work with.
The file will be imported into another App so it is looking for specific columns, if there are more columns than ii si looking for it will spit the dummy.
 
Upvote 0
Hi jag108:

I don't see any problem converting the logic of the formula in use with VBA ... however

how do you want to set it up?

where would the StartTime be noted?

where would the Duration be noted?

and where would the computed NextStartTime be noted?

It will be nice to see what is your setup and how your data is displayed ... please consider posting an HTML screenshot of your sample data.
 
Upvote 0
Hi Yogi,

I need to verify the start time to the duration so that we do not have an overlap of events, this is critical for the application that is importing the data. The data is laid out col A = Date, col B = start time, col C = duration.
Import_checker5.xls
ABCD
101-12-0518:0000:30NewAmericanSportsman
201-12-0518:3000:30Fishing
301-12-0519:0000:30AroundtheHorn
401-12-0519:3000:30PardontheInterruption
501-12-0520:0001:00SportscenterLIVE
601-12-0521:0000:30ATPTennisWeekly
701-12-0521:3000:30PardontheInterruption
801-12-0522:0001:00IceSkating
901-12-0523:0002:30Golf
1001-12-0525:3000:30PardontheInterruption
1101-12-0526:0002:00Sportscenter
1201-12-0528:0001:30DragRacing
1301-12-0529:3000:30NFLFilmsPresents
1402-12-0506:0000:30NewAmericanSportsman
1502-12-0506:3000:30MotorsportAsia
1602-12-0507:0000:30DivingPassport
1702-12-0507:3000:30ATPTennisWeekly
1802-12-0508:0000:30ESPNFitnessPros
1902-12-0508:3000:30Anthology
DFU Template IBMS with formula
 
Upvote 0
Hi jag108:

I have made a little modification to your layout (hopefully that will not cause any problems) ... well first let us look at the proposed solution ...
y051122h1.xls
ABCD
1starting values shown in light green
201-Dec-0518:000
301-Dec-0518:000:30New American Sportsman
401-Dec-0518:300:30Fishing
501-Dec-0519:000:30Around the Horn
601-Dec-0519:300:30Pardon the Interruption
701-Dec-0520:001:00Sportscenter LIVE
801-Dec-0521:000:30ATP Tennis Weekly
901-Dec-0521:300:30Pardon the Interruption
1001-Dec-0522:001:00Ice Skating
1101-Dec-0523:002:30Golf
1201-Dec-0525:300:30Pardon the Interruption
1301-Dec-0526:002:00Sportscenter
1401-Dec-0528:001:30Drag Racing
1501-Dec-0529:300:30NFL Films Presents
1602-Dec-056:000:30New American Sportsman
1702-Dec-056:300:30Motorsport Asia
1802-Dec-057:000:30Diving Passport
1902-Dec-057:300:30ATP Tennis Weekly
2002-Dec-058:000:30ESPN Fitness Pros
2102-Dec-058:300:30Anthology
2202-Dec-05
Sheet6 (2)


formula in cell A3 is ... =INT($A2)+($B2+$C2)/("30:00")

and formula in cell B3 is ... =MOD(B2+C2,"30:00"+0)

these are then copied down
 
Upvote 0
I do something simular. This make work for your situation.

I have times listed. Then we have breaks in 30 minute increments.

A B
12:00 AM 30
12:30 AM 30
1:00 AM 60
2:00 AM 120
4:00 AM 60
5:00 AM 30
5:30 AM 30
6:00 AM 120
8:00 AM

My formula starting in Cell A2 (The Bold Cell) is:

=A1+(B1/1440)

This adds whatever is entered in column B in the last row.


Hope this helps,
Michael
 
Upvote 0
Hi Yogi,

You understand my issue, but I cannot use the formula you are proposing, for the sheer sake it does not do what I require. I cannot change the layout of the file ata all due to it is what the import program is expecting, if anything is out of sequence it will fail. The code I posted ealrier in the post is what I need to do.
becuse the spread sheet will be simply just data I will have the code in another sheet that will prompt the user to open the data sheet, so tha it can run over the start time calculate it to the duration then compare this to the next start time, if there is an error then prompt the user that there is an issue with that particular event. So the formula idea may work but is not usable in my situation, sorry! :(

If that could be turned into simple VBA then how?
 
Upvote 0

Forum statistics

Threads
1,214,374
Messages
6,119,155
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top