Calculate hours more than 12:00 PM Excel VBA

primasatria

New Member
Joined
Dec 3, 2023
Messages
9
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Dear all,

I have time in (TextBox1) with value 06:00 PM and time out (Textbox2) with value 01:00 AM.
And result in Textbox3.

How to calculate in Excel Userform?

If time in 06:00 AM and time out 05:00 PM, the result is correct 09:00

If time in 06:00 PM and time out 12:00 PM, the result is correct 06:00

But if time in 06:00 PM and time out 01:00 AM, the result is wrong 17:00, not 07:00

I need your kind assistance and helping hands.

Thank you,
Prima Indonesia
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Test if your time out is less than your time in and if it is add 1 (=1 day) to your time out before subtracting your time in.
 
Upvote 0
From 6:00 AM to 5:00 PM should be 11 hours, not 9
and from 6:00 PM to 12:00 PM it should be 18 hours, not 6.

Libro4
CDE
1InOutOut - In
26:00 PM1:00 AM7:00
36:00 AM5:00 PM11:00
46:00 PM12:00 PM18:00
Hoja1
Cell Formulas
RangeFormula
E2:E4E2=IF(D2<C2,D2+1-C2,D2-C2)
 
Upvote 0
In an Excel formula, you don't need all that: =MOD(D2-C2,1) will suffice.
But the op wants VBA.
What code do you have right now?
 
Upvote 0
I wasn't proposing to use a formula I was showing him the correct results he should expect
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

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