# Returning Nothing If Two Values are Empty by Allen Wyatt
(last updated May 10, 2019)

Graham uses a formula that references two cells, B1 and C1. All the formula does is to return the value of one of the cells, as in =IF(A1=1,IF(B1>C1,B1,C1)). Both B1 and C1 normally contain dates, but sometimes either or both of them may be empty. If they are both empty, the returned value (which is 0 because they are empty) shows up as 1/0/1900. When both cells are empty Graham would like the formula to return a blank value, not a 0.

There are several ways that this need can be approached. First, though, let's start with Graham's example formula:

```=IF(A1=1, IF(B1>C1, B1, C1))
```

The formula is a bit "incomplete," as it doesn't provide what should be returned if A1 does not contain the value 1. As written, if A1 contains 2 (or any other value except 1), then the formula returns "FALSE". So, let's modify the formula just a bit so that if A1 is not 1 that it returns a "blank" value, like this:

```=IF(A1=1, IF(B1>C1, B1, C1), "")
```

Next it is key to understand what is happening in the "B1>C1" comparison. Dates are, of course, stored internally as numeric values—as serial numbers. If B1 contains a date that is more recent than C1, then the serial number in B1 will be larger than the serial number in C1. Beyond this, the characteristics of the data in B1 and C1 determine how the comparison (>) works.

1. If both of the cells contain numeric values (including dates), then the comparison works as expected.
2. If either of the cells contains a text value, then both cells are treated as if they contain text values, even if one of them contains a numeric value.
3. If one of the cells is empty, then that cell is treated as if it contains the value 0.

Based on this, if one cell contains a date and the other is empty it is equivalent to comparing a serial number (the date) against a 0 (the empty cell), so the serial number will always be greater than the empty cell. If both cells are empty, both are treated as containing 0, and therefore both are equal.

So, let's say that in Graham's formula, cell A1 contains the value 1, cell B1 is empty, and cell C1 is empty. This is how the formula is "translated" by Excel:

```=IF(A1=1, IF(B1>C1, B1, C1), "")
=IF(1=1, IF(B1>C1, B1, C1), "")
=IF(B1>C1, B1, C1)
=IF(0>0, B1, C1)
=C1
=0
```

This is why Graham is seeing 0 returned by the formula, and when 0 is considered to be a date serial number, it is displayed as 1/0/00 (or 1/0/1900).

To avoid this, you need to check to see if both B1 and C1 are empty. There are any number of ways this can be done. Consider this variation on his formula:

```=IF(A1=1, IF((B1+C1=0), "", IF(B1>C1, B1, C1)), "")
```

This variation adds an IF statement to see if B1 added to C1 is equal to 0, which it will be if both of them are blank because Excel considers the blanks and 0 to be equivalent in this context. The drawback is that if either B1 or C1 contains a text value, then the #VALUE error is returned by the formula.

A better variation may be the following:

```=IF(A1=1, IF(AND(B1=0,C1=0), "", IF(B1>C1, B1, C1)), "")
```

In this incarnation the IF statement uses the AND function to determine if both B1 and C1 are 0. This also solves the potential #VALUE error issue.

If you really want to check whether both B1 and C1 are empty, then you'll need to rely on a different approach. One way is to use the COUNTA function:

```=IF(A1=1, IF(COUNTA(B1:C1)=0, "", IF(B1>C1, B1, C1)), "")
```

If you know for a fact that both B1 and C1 will never contain text values at the same time, you could also use the COUNT function in place of the COUNTA function in the foregoing formula.

Another approach is to use the COUNTBLANK function in much the same way; it returns a count of the number of cells in a range that are empty:

```=IF(A1=1, IF(COUNTBLANK(B1:C1)=2, "", IF(B1>C1, B1, C1)), "")
```

A similar variation is to use the ISBLANK function (which returns TRUE if a cell is blank) along with the AND function:

```=IF(A1=1, IF(AND(ISBLANK(B1), ISBLANK(C1)), "", IF(B1>C1, B1, C1)), "")
```

You could also have Excel evaluate B1 and C1 as if they contained text, as is done here:

```=IF(A1=1, IF(B1&C1="", "", IF(B1>C1, B1, C1)), "")
```

This formula won't work as expected if either B1 or C1 contain a single space, so you might want to add the TRIM function into the mix:

```=IF(A1=1, IF(TRIM(B1&C1)="", "", IF(B1>C1, B1, C1)), "")
```

In any of the formulas discussed so far, you may also want to change the IF statement that returns B1 or C1 with the MAX function, in this manner:

```=IF(A1=1, IF(TRIM(B1&C1)="", "", MAX(B1:C1)), "")
```

There is one caveat if you decide to do this, however: The MAX function considers all text values to be equivalent to 0. Thus, if cell B1 contains "abc" and cell C1 contains 1, then using the greater than comparison operater (>) considers "abc" as greater than 1, but MAX considers 1 as greater than "abc".

There is also a way that you could go back an use Graham's original formula (the one that doesn't check for two blank cells) and simply rely on formatting the cell containing the formula. Just create a custom format such as the following:

```m/d/yyyy;;
```

Notice the two semicolons at the end of the format. These tell Excel to not display anything if the value in the cell is negative or a zero value. Using this format you would never see the date 1/0/1900 appear; the cell would show as blank.

You could, of course, modify Excel so that it hides all zero values in the worksheet—as has been covered in other ExcelTips—but doing so may not suit your purposes if you need to display zero results from other formulas.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10386) applies to Microsoft Excel 2007, 2010, and 2013.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Printing Workbook Properties

Want to create a printed record of the properties associated with a workbook? There is no easy way to do it in Excel. ...

Discover More

Graphics and Line Height

If the inline graphics in your document appear "chopped off," it could be directly related to the formatting within the ...

Discover More

Unwanted Page Breaks in Cross-References

You can use fields to cross-reference different text in a document. If you get unwanted results from the ...

Discover More Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

##### More ExcelTips (ribbon)

Calculating a Group Retirement Date

Calculating a retirement date can be as simple as doing some date math to see when a person reaches a certain age. ...

Discover More

Converting Coded Dates into Real Dates

Sometimes the format in which you receive data is not the same format that would be optimal for Excel. For instance, you ...

Discover More

Excel allows you to perform quite a few operations using dates in your worksheet. Sometimes, however, the answer may not ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 - 2?

2019-05-10 11:35:16

Dave Bonin

Oooh! This is a trigger point for me.

I never use "" as the results of a formula. Why? Because I can't tell whether an apparently blank cell is really blank or if it's the result of a formula WITHOUT me actually examining the individual cell to see if it has a formula.

Personally, I prefer using the "•" character instead (ALT-0149), along with some special custom number formatting,

Custom number formatting??? Yes. I typically use "[Color15]" for the text portion of a custom number format to shade any text light gray. Two examples are "0.000;-0.000;0;[COLOR15]" and "0.00_);[RED](0.00);0_._0_0_);[Color15]" On most systems, Color 15 is light gray.

Why use light gray? It allows me to see the dots while not making them too visible. It provides visual help without clutter. Plus I found users are pretty good at not questioning dots where they might question an apparently blank cell.

In many cases, I write formulas to check whether we have all necessary parameters and that they're all valid before the formula gives a numeric result. If we don't have all the numbers needed to calculate a full result, the formula returns a "•". This helps avoid #DIV/0 errors and misleading results due to missing data. Remember, the First Rule of Excel Non-Acceptance: All workbooks with error values are suspect.

2017-03-22 16:34:57

Zee

Hi - I'm setting up a spreadsheet that will help calculate various deadlines and denote when deadlines were met and when they weren't. It's based on the final deadline with various calculations for each phase deadlines.

- Deadline #1 starts with the Final Deadline (set in column D) and subtracts 8 days for the initial item submission.
Excel Formula =WORKDAY(\$D2,-8)

- Actual date received is a firm date.

- Difference between the two dates, which could be a positive or negative number if they met or missed the deadline set.
Excel Formula =NETWORKDAYS(H2,I2)

- Denotation of Met/Missed Deadline is formatted as wording - Yes or No - based on the previous calculations
Excel Formula =IF(J2<=-1,"No","Yes")

My problem is that I get the Serial Numbers when one of the columns is blank AND it also puts the Yes/No in the met or missed deadlines column. I want no wording and no differences reflected if either of the fields is blank. When I tried several of the formula strings noted above, I got error message of incorrect formula.

My preference is for there to be an empty field when there is no real data to calculate one of the dte fields.

Thank you

2017-02-22 09:12:21

Sudhaa

=IF(ISERROR(INDEX(PunchTime!\$B\$2:\$D\$5000,SMALL(IF(PunchTime!\$B\$2:\$B\$5000&PunchTime!\$C\$2:\$C\$5000=\$P\$4&B6,ROW(PunchTime!\$B\$2:\$D\$5000)),ROW(\$1:\$1)),3)),TEXT(B8,"dddd"),INDEX(PunchTime!\$B\$2:\$D\$5000,SMALL(IF(PunchTime!\$B\$2:\$B\$5000&PunchTime!\$C\$2:\$C\$5000=\$P\$4&B6,ROW(PunchTime!\$B\$2:\$B\$5000)),ROW(\$1:\$1)),3))
i am having the above formula in D column and i want in H column returns the value or if in D it is text like Sunday or Saturday then H = 0
and I can replace TEXT(B8,"dddd") to "" then D is blank for the same Result H=o
how can achieve this
Thanks for the helper

2015-07-11 12:34:42

Mike Day

I find that Custom formats are often useful for this type of problem. These let you specify what to show when the result is positive, negative, zero, or a text value. It works equally well for dates as for numbers or currency values.
Set zero to be displayed as a blank or something else. I often use a minus sign. It is unobtrusive but lets you spot those occasions when the formula is missing from the cell because it has been accidentally deleted or an extra row was inserted and you forgot to copy down the formula.

2015-07-11 06:43:26

Dr Rajeev Sharma

Dear Sir

I have been trying to work on a formula that contains several parameter. I tried using the above stated method as well but seems like I would need more tips. Could you please help me do that?

regards
Rajeev

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.