HOUR(IF(AND( Formula Help... Please!!

XL1980

New Member
Joined
Apr 22, 2016
Messages
6
Hi,

I am having problems combining the HOUR, IF and AND functions in a formula and I'm hoping someone can assist.

In cell A1, I have 09:00 and in cell A2 I have 17:00. Cell A3 has the following formula: =HOUR(A2-A1-1). This gives me 7.00 hours which is what I want. The '-1' is used to subtract a lunch hour.

What I want cell A3 to do is to only calculate the number of hours-1 when there is ONLY a value in both A1 & A2. If there isn't a value in cells A1 & A2 and I use the formula =HOUR(A2-A1-1), it gives me -1.00 (obviously).

I have tried the following formula in cell A3: =HOUR(IF(AND(A1<>"",A2<>""),A2-A1-1,"")). The answer I get is #VALUE!

Then, if I enter in cell A1 09:00 and in cell A2 17:00, cell A3 shows #NUM!.

I've exhausted searching on Google. Can anyone help?

Thank you.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
try

=IF(COUNT(A1:A2)=2,HOUR(A2-A1)-1,"")
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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