Time subtraction

Wolfin2010

New Member
Joined
Feb 21, 2015
Messages
23
Office Version
  1. 365
Platform
  1. Windows
What I'm trying to do is, if total hours are less than 4 hrs give me the answer 4:00 otherwise subtract D-C

=IF(OR(INDIRECT("D"&ROW())="",INDIRECT("C"&ROW())=""),"",IF((INDIRECT("D"&ROW())-INDIRECT("C"&ROW())*24)>"4","4:00",TIME(HOUR(INDIRECT("D"&ROW())),MROUND(MINUTE(INDIRECT("D"&ROW())),15),0)-TIME(HOUR(INDIRECT("C"&ROW())),MROUND(INDIRECT("C"&ROW()),15),0)))

problem I'm getting is if the hrs are less than 4, I get exact answer not 4:00

=IF(OR(INDIRECT("D"&ROW())="",INDIRECT("C"&ROW())=""),"",IF((INDIRECT("D"&ROW())-INDIRECT("C"&ROW())*24)<"4","4:00",TIME(HOUR(INDIRECT("D"&ROW())),MROUND(MINUTE(INDIRECT("D"&ROW())),15),0)-TIME(HOUR(INDIRECT("C"&ROW())),MROUND(INDIRECT("C"&ROW()),15),0)))

I get answer 4:00 regardless the answer.

Any suggestions?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try
Excel Formula:
=MAX(D2-C2,"04:00:00"+0)
formatted as [h]:mm:ss
 
Upvote 0
Try
Excel Formula:
=MAX(D2-C2,"04:00:00"+0)
formatted as [h]:mm:ss
Thanks for the reply

=MAX(INDIRECT("D"&ROW())-INDIRECT("C"&ROW()),"4:00")

Does work but it does not round up the minutes so I tried

=IF(MAX(INDIRECT("D"&ROW())-INDIRECT("C"&ROW()),"4:00"),"4:00",TIME(HOUR(INDIRECT("D"&ROW())),MROUND(MINUTE(INDIRECT("D"&ROW())),15),0)-TIME(HOUR(INDIRECT("C"&ROW())),MROUND(MINUTE(INDIRECT("C"&ROW())),15),0))

Which keeps on giving me the same answer 4:00

Time format is [h]:mm
 
Upvote 0
Why are you using INDIRECT()? That is causing the formula to break.

edit:- ignore that, I misread what you were trying to do, although use of indirect should not be necessary.
Excel Formula:
=MAX(MROUND(D2-C2,1/1440),"04:00:00"+0)
 
Last edited:
Upvote 0
I will be adding the formula in Name Manager for that I'm using Indirect
 
Upvote 0
Makes sense now
Excel Formula:
=MAX(MROUND(INDIRECT(RC4,0)-INDIRECT(RC3,0),1/1440),"04:00:00"+0)
 
Upvote 0
Makes sense now
Excel Formula:
=MAX(MROUND(INDIRECT(RC4,0)-INDIRECT(RC3,0),1/1440),"04:00:00"+0)

Thank you very much it's providing the right value. one more question how can I modify formula so D2-C2 will give me the right value (6:45) not 4:00
C2D2
24-11-2020 5:45:00 PM25-11-2020 12:30:00 AM
 
Upvote 0
There was a typo in my formula which might be causing the problem, I would have expected an error but the difference might be due to you having it in a named range. This will work correctly with either.
Book1
CDE
224/11/2020 17:5525/11/2020 00:3006:35:00
Sheet1
Cell Formulas
RangeFormula
E2E2=MAX(MROUND(INDIRECT("RC4",0)-INDIRECT("RC3",0),1/1440),"04:00:00"+0)
 
Upvote 0
Book1
K
210:30
Sheet1
Cell Formulas
RangeFormula
G2:G3, K2:K3G2=MAX(TIME(HOUR(INDIRECT("D"&ROW())),MROUND(MINUTE(INDIRECT("D"&ROW())),15),0)-TIME(HOUR(INDIRECT("C"&ROW())),MROUND(MINUTE(INDIRECT("C"&ROW())),15),1/1440),"04:00:00"+0)
H2:H3H2=MAX(MROUND(D2-C2,1/1440),"04:00:00"+0)
I2:I3I2=IF(INT((D2-C2)*24)<4,"4:00",TIME(HOUR(D2),MROUND(MINUTE(D2),15),0)-TIME(HOUR(C2),MROUND(MINUTE(C2),15),0))
J2:J3J2=MAX(MROUND(INDIRECT("RC4",0)-INDIRECT("RC3",0),1/1440),"04:00:00"+0)
E2:E3E2=IF(OR(INDIRECT("C"&ROW())="",INDIRECT("D"&ROW())=""),"",INDIRECT("D"&ROW())-INDIRECT("C"&ROW()))


having problem with the minutes round up.
 
Last edited:
Upvote 0
Something went wrong with your last post, the example sheet is not showing correctly. Should the minutes be rounding up or rounding to nearest?

If you always want to round up then you would need to use CEILING instead of MROUND.
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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