What do you see if you select columns E and F, and set the number property to General?
Using IF function and calculation for time in hours and minutes
We will be paying out any employees who have over 40 hours of vacation. I cannot seem to get the formula to work. My formula is: =IF(E2>F2,E2-F2,0). As you can see in the screen shot, it works most of the time but there are a few that show up as ####. All of the cells are formatted as [h]:mm. Any ideas?
Microsoft 365 and Office | Excel | For business | Windows
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
6 answers
Sort by: Most helpful
-
-
Anonymous
2022-11-30T22:25:18+00:00 Same result
-
HansV 462.4K Reputation points MVP Volunteer Moderator2022-11-30T22:34:08+00:00 Oh - I see now. The values are left-aligned while the Alignment group on the Home tab of the ribbon shows that no specific horizontal alignment has been set.
The values aren't time values but text values. When evaluating E2>F2, Excel compares the values as text. and since "5" comes after "4", "5:09" is seen as greater than "40:00".
Use
=MAX(TIMEVALUE(E3)-TIMEVALUE(F3),0)
-
HansV 462.4K Reputation points MVP Volunteer Moderator2022-11-30T23:06:58+00:00 Try this in G2:
=MAX(1*E2-1*F2,0)
Another option is to convert columns E and F to real time values:
Select column E.
On the Data tab of the ribbon, click Text to Columns.
Without changing any settings, click Finish.
Do the same for column F.
You can then use =MAX(E2-F2,0)