Macro for calculating hours between two times

Abriel

New Member
Joined
Aug 30, 2016
Messages
2
Hi,
Someone can help to me?
I have two time data in column E and column F
For example:
ColumnE
12:30

ColumnF
18:11

The rule is the following:
If StartTime is greater than 12:00pm, then show total hours (column Q) between 18:00 and 22:00

So 12:30 and 18:11 -> 0:11
or 14:15 and 21:15 -> 03:15
or 18:15 and 04:05 -> 03:45

And there is another rule:
If StarTime is greater than 12:00pm, then show total hours (column R) between 22:00 and 06:00

I tried lot of ways in VBA,but it's too complex for me.
Can somebody help to me?
 
A non VB approach:


Excel 2010
EFGHIJKL
Start TimeEnd TimeCol QCol RTime1Time2
Start
End

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]12:30[/TD]
[TD="align: right"]18:11[/TD]
[TD="align: right"][/TD]
[TD="align: right"]0:11[/TD]
[TD="align: right"]0:00[/TD]

[TD="align: right"]0.75[/TD]
[TD="align: right"]0.916667[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]14:15[/TD]
[TD="align: right"]21:15[/TD]
[TD="align: right"][/TD]
[TD="align: right"]3:15[/TD]
[TD="align: right"]0:00[/TD]

[TD="align: right"]0.916667[/TD]
[TD="align: right"]1.25[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]18:15[/TD]
[TD="align: right"]4:05[/TD]
[TD="align: right"][/TD]
[TD="align: right"]3:45[/TD]
[TD="align: right"]6:05[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet2

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]H2[/TH]
[TD="align: left"]=MIN((F2<E2)+F2,$K$3)-MAX(E2,$K$2)[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: #DAE7F5"]I2[/TH]
[TD="align: left"]=MAX(0,MIN((F2<E2)+F2,$L$3)-MAX(E2,$L$2))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

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