Adding time from a list of starts and stops to come up with a single start/stop

kgartin

Board Regular
Joined
May 6, 2010
Messages
207
Office Version
  1. 365
Platform
  1. Windows
I have start times listed in column A and corresponding stop times in column B

I need a macro to calculate all the elapsed time and create a new stop time adding all of the elapsed time together.

So if:

A1 = 12:00 PM
B1 = 1:15 PM

A2 = 1:30 PM
B2 = 2:15 PM

A3 = 10:00 PM
B3 = 1:30 AM

Total elapsed time = 5.5 hours

Need code to give original start time (12:00 PM from A1) but come up with new stop time of 5:30 PM based on the elapsed time(s). I'll be assigning the result to a variable.

How do I calculate this properly? It sounds simple but for some reason it's twisting me up...
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Maybe...

Code:
Sub aTest()
    Dim LR As Long
    Dim dbStart As Double, dbElapsed As Variant, dbStop As Double
        
    dbStart = Range("A1")
    LR = Cells(Rows.Count, "A").End(xlUp).Row
    dbElapsed = Evaluate("=SUMPRODUCT(MOD(B1:B" & LR & "-A1:A" & LR & ",1))")
    dbStop = dbStart + dbElapsed
    MsgBox Format(dbStop, "hh:mm AM/PM")
End Sub

Hope this helps

M.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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