In Excel, I need to return a value of 1 if a referenced cell is empty
I can do it if the value is zero but how do I do it if it is empty?
You may have to use =IF(ISNUMBER(A1),A1,1) in some situations where you are looking for number values in cell.
P4 is the cell I test for:
=IF(ISBLANK(P4),1,0)
=if(a1="","1","0")
In this formula if the cell is empty then the result would be 1 else it would be 0
Paxdiablo's answer is absolutely correct.
To avoid writing the return value 1 twice, I would use this instead:
=IF(OR(ISBLANK(A1),TRIM(A1)=""),1,0)
Since required quite often it might as well be brief:
=1*(A1="")
This will not return 1 if the cell appears empty but contains say a space or a formula of the kind =IF(B1=3,"Yes","") where B1 does not contain 3.
=A1="" will return either TRUE or FALSE but those in an equation are treated as 1 and 0 respectively so multiplying TRUE by 1 returns 1.
Much the same can be achieved with the double unary --:
=--(A1="")
where when A1 is empty one minus negates TRUE into -1 and the other negates that to 1 (just + in place of -- however does not change TRUE to 1).
If you've got a cell filled with spaces or blanks, you can use:
=Len(Trim(A2)) = 0
if the cell you were testing was A2