Excel Help: Count a cell if another cell is not blank

Difficulty: NO MACROS

“Count” the cell is probably the wrong term when talking Excel. I want to do this:

Cell A1 has a number value.
Cell B1 may be blank or not blank.
I want Cell C1 to have value of Cell A if and only if Cell B is not blank.

So, like, Cell C1 =A1 IFF B1 not blank.

How do I do this, without a macro. Thanks!!

C1 should hold =IF(ISBLANK(B1),A1,"")

Note a cell with just a space in it is not considered blank so be careful.

I think it should be swapped. That is =IF(ISBLANK(B1),“”,A1)

OP wants something to happen if it’s not blank.

You may also be able to say =IF(B1=“”,“”,A1)
I might be off on the syntax, but I think that will say if B1 is blank, then leave it alone, else A1.
I’m sure there’s differences, but this one might be a bit more straightforward. Also, it gives you the ability to easily change it from checking to see if it’s blank to checking to see if it contains some specific value.

You guys are awesome. Thanks!

Alternative to swapping:
= IF(NOT(ISBLANK(B1)),“”,A1)

I wasn’t sure how much programming experience the OP has. A little bit of high school BASIC goes a loooong way with this kind of thing. In any case, I actually did (intentionally) sneak that in.

Does Excel have a Trim command? That might work to read spaces as being empty strings.

It does but =ISBLANK(Trim(a1)) returns a FALSE if a1 contains only a space.
TRIM doesn’t remove spaces between words and I guess it interprets a single space as “between words”

I’m sure there’s a way to nest these different functions into a single formula, but if there might be any spaces or other invisible characters in your “blank” column, it could be more intuitive to perform two separate steps: first copy column B and “cleanse” the copy, then use your ISBLANK formula on the cleansed column.

Various ways to clean up any spaces are shown here.

This works for hidden blank spaces in OpenOffice, haven’t tried it in Excel:

=IF(LEN(TRIM(C21)) > 0; B21; “”)

Should return blank if C21 is actually blank or contains only blank spaces, otherwise the other cell.

There is also an ISNUMBER command that could replace ISBLANK if you want B1 to be strictly a number.