Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excel - if cell is not blank, then do IF statement

Tags:

excel

I have this simple statement in excel. I compare two dates. If the date 2 is greater than or equal to date 1, then I show 1. If not, then I show 0.

However, I would like to apply this function only when the cells contains text:

IF(NOT(ISBLANK((Q2<=R2;"1";"0")))

That gives me an error - what am I doing wrong?

like image 405
oliverbj Avatar asked Mar 05 '15 13:03

oliverbj


People also ask

How do you write an IF THEN formula in Excel?

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")

Is there an if/then else function in Excel?

The Microsoft Excel IF-THEN-ELSE statement can only be used in VBA code. It executes one set of code if a specified condition evaluates to TRUE, or another set of code if it evaluates to FALSE. The IF-THEN-ELSE statement is a built-in function in Excel that is categorized as a Logical Function.

How do you leave a cell blank if the reference cell is blank?

Keep cell blank until data entered in Select first cell that you want to place the calculated result, type this formula =IF(OR(ISBLANK(A2),ISBLANK(B2)), "", A2-B2), and drag fill handle down to apply this formula to the cells you need.


1 Answers

Your formula is wrong. You probably meant something like:

=IF(AND(NOT(ISBLANK(Q2));NOT(ISBLANK(R2)));IF(Q2<=R2;"1";"0");"")

Another equivalent:

=IF(NOT(OR(ISBLANK(Q2);ISBLANK(R2)));IF(Q2<=R2;"1";"0");"")

Or even shorter:

=IF(OR(ISBLANK(Q2);ISBLANK(R2));"";IF(Q2<=R2;"1";"0"))

OR EVEN SHORTER:

=IF(OR(ISBLANK(Q2);ISBLANK(R2));"";--(Q2<=R2))
like image 82
ttaaoossuuuu Avatar answered Sep 21 '22 10:09

ttaaoossuuuu