Forum Discussion
How do you write a formula that must have two conditions met?
Hello,
if you want to check if both cells contain numbers, you can use Count(). Combine that with your existing condition like this:
=IF(or(D1-C1<0,count(C1:D1)=0),"",D1-C1)
Or, written another way:
=if(and(Count(C1:D1)=2,D1-C1>0),D1-C1,"")
In words: if both cells C1 and D1 contain a number AND if at the same time the result of the subtraction is greater than 0, then perform the subtraction, else return a blank.
Does that help?
Thank you!! Im going to give this a try. If I may, Id like to ask exactly what this formula is saying, and what is the purpose of the =if(and(Count(C1:D1)=2,D1-C1>0),D1-C1,"") part of the formula? I want to fully understand what the language is, rather than lean on everyone. Your help is greatly appreciated!
- Jun 10, 2018
Hello,
the Count() function counts the cells that have numbers (not text). So, in this formula, if the Count() of cells C1 to D1 returns the result 2, that means that both of these cells contain a number. Used in an IF() statement, Count is a great way to ensure that a calculation is only performed when all required input cells have been filled in.