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

**URL:** <https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735>\
**Category:** Factual Questions\
**Created:** [April 30, 2022, 8:38pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735 "2022-04-30T20:38:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bear\_Nenno](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bear_nenno/32/3358_2.png) [@Bear\_Nenno](https://boards.straightdope.com/u/Bear_Nenno)\
**Post date:** [April 30, 2022, 8:38pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/1 "2022-04-30T20:38:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [April 30, 2022, 8:46pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/2 "2022-04-30T20:46:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Joey\_P](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@Joey\_P](https://boards.straightdope.com/u/Joey_P)\
**Post date:** [April 30, 2022, 8:48pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/3 "2022-04-30T20:48:48Z")

</div>

> [@OldGuy](#):
>
> C1 should hold =IF(ISBLANK(B1),A1,“”)

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.

---

<div class="post-metadata">

**Author:** ![Bear\_Nenno](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bear_nenno/32/3358_2.png) [@Bear\_Nenno](https://boards.straightdope.com/u/Bear_Nenno)\
**Post date:** [April 30, 2022, 8:51pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/4 "2022-04-30T20:51:02Z")

</div>

You guys are awesome. Thanks!

---

<div class="post-metadata">

**Author:** ![Machine\_Elf](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Machine\_Elf](https://boards.straightdope.com/u/Machine_Elf)\
**Post date:** [April 30, 2022, 10:39pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/5 "2022-04-30T22:39:31Z")

</div>

> [@Joey\_P](#):
>
> I think it should be swapped. That is =IF(ISBLANK(B1),“”,A1)
> 
> OP wants something to happen if it’s not blank.

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

---

<div class="post-metadata">

**Author:** ![Joey\_P](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@Joey\_P](https://boards.straightdope.com/u/Joey_P)\
**Post date:** [April 30, 2022, 10:51pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/6 "2022-04-30T22:51:01Z")

</div>

> [@Machine\_Elf](#):
>
> 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.

> [@Joey\_P](#):
>
> OP wants something to happen if it’s **not blank**.

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [May 1, 2022, 12:29am UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/7 "2022-05-01T00:29:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [May 1, 2022, 1:04am UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/8 "2022-05-01T01:04:41Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Briny\_Deep](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/briny_deep/32/17188_2.png) [@Briny\_Deep](https://boards.straightdope.com/u/Briny_Deep)\
**Post date:** [May 1, 2022, 1:20am UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/9 "2022-05-01T01:20:37Z")

</div>

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](https://www.ablebits.com/office-addins-blog/remove-spaces-excel/).

---

<div class="post-metadata">

**Author:** ![Ludovic](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Ludovic](https://boards.straightdope.com/u/Ludovic)\
**Post date:** [May 1, 2022, 1:21am UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/10 "2022-05-01T01:21:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mcgato](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@mcgato](https://boards.straightdope.com/u/mcgato)\
**Post date:** [May 2, 2022, 12:20pm UTC](https://boards.straightdope.com/t/excel-help-count-a-cell-if-another-cell-is-not-blank/963735/11 "2022-05-02T12:20:10Z")

</div>

> [@OldGuy](#):
>
> C1 should hold =IF(ISBLANK(B1),A1,“”)

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