oliverbj
oliverbj

Reputation: 6052

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

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?

Upvotes: 6

Views: 121033

Answers (2)

ttaaoossuu
ttaaoossuu

Reputation: 7884

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))

Upvotes: 10

uTeisT
uTeisT

Reputation: 2266

You need to use AND statement in your formula

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

And if both conditions are met, return 1.

You could also add more conditions in your AND statement.

Upvotes: 1

Related Questions