Date diff with multiple conditions

WillSTARK

New Member
Joined
Jan 25, 2017
Messages
13
Hi,

Currently I am computing the date difference in days using this formula (which works): =if(and(ISNUMBER(W2),ISNUMBER(H2)),W2-R2,"")

However, I would like to restrain the output and only consider values between 5 and 150.
So I would like the function to say If W2 isnumber and if H2 isnumber then, W2 - R2, "" and if W2 - R2 isnot between 5 and 150 range, ""

I tried various tweak but I did not manage to get it right, so any help would be appreciated.

Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Welcome to the forum!

Maybe:
=IF(AND(ISNUMBER(W2),ISNUMBER(H2)),IF(OR(W2-R2<5,W2-R2>150),"",W2-R2),"")

Or slightly shorter:
=IF(COUNT(W2,H2)=2,IF(OR(W2-R2<5,W2-R2>150),"",W2-R2),"")
 
Upvote 0
Hi,
Thank you for your reply, it works! Instead of the 'OR' I had 'and', and forgot the "" in the end.
Thanks a lot,
Cheers
 
Upvote 0
Hi,
I believe it was a mistake. The formula works, but I changed R2 to H2. You are right the first two cells verified as Isnumber should be the one used afterwards.
Hi there,

Just curious, why not check if R2 is a number?

Mark
 
Upvote 0
Instead of the 'OR' I had 'and'

Hi, you could do it with AND() by switching the equality tests - and thinking about it, you could do away with the nested IF() - not that it saves that much.

=IF(AND(COUNT(W2,R2)=2,W2-R2>=5,W2-R2<=150),W2-R2,"")
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,826
Members
449,051
Latest member
excelquestion515

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