You can use:
=IF(ISBLANK(A1),1,0)
but you have to be careful what you mean by an empty cell. I have been caught this before. If you want to know if the cell is really empty, isblank will work as above. Unfortunately, sometimes you also need to know if it does not contain any useful data.
Expression:
=IF(ISBLANK(A1),TRUE,(TRIM(A1)=""))
will return true for cells that are really empty or contain only a space.
Here are the results, when column A contains different numbers of spaces, column B contains length (so you know how many spaces) and column C contains the result of the expression:
<-A-> <-B-> <-C-> 0 TRUE 1 TRUE 2 TRUE 3 TRUE 4 TRUE 5 TRUE a 1 FALSE <-A-> <-B-> <-C->
Return 1 if the cell is empty or a space, and 0 otherwise:
=IF(ISBLANK(A1),1,if(TRIM(A1)="",1,0))
will do the trick.
This trick comes in handy when the cell you are checking is actually the result of an Excel function. Many Excel functions (such as trim) return an empty string, not an empty cell.
You can see it in action with a new sheet. Leave cell A1 as it is and set A2 to =trim(a1) .
Then set B1 to =isblank(a1) and B2 to isblank(a2) . You will see that the former is true, and the latter is untrue.
paxdiablo Mar 16 '10 at 7:10 2010-03-16 07:10
source share