Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Conditional Formats that Distinguish Blanks and Zeroes.

Conditional Formats that Distinguish Blanks and Zeroes

by Allen Wyatt
(last updated June 21, 2018)

6

Let's say that you routinely import information from another program into Excel. The information contains numeric values, but it can also contain blanks. You might want to use a conditional format on the imported information to highlight any zero values. The problem is, if you just add a conditional format that highlights the cells to see if they are zero, then the condition will also highlight any cells that are blank, since they contain a "zero" value, as well.

There are several different solutions to this predicament. One solution is to apply a conditional format that uses two conditions. The first condition checks for the blanks, and the second checks for zero values. The condition that checks for blanks doesn't need to adjust any formatting, but the one that checks for zero values can. This works because if the first condition is satisfied (the cell is blank), the second condition is never tested. Do the following:

  1. Select the range you want conditionally formatted. (For this example, I'll assume that you've selected the range A2:A99.)
  2. Choose Conditional Formatting from the Format menu. Excel displays the Conditional Formatting dialog box.
  3. Using the first drop-down list for Condition 1, choose Formula Is.
  4. In the formula box for Condition 1, enter the formula =ISBLANK(A2). (See Figure 1.)
  5. Figure 1. The Conditional Formatting dialog box after setting one condition.

  6. Click Add. Excel adds a second condition to the dialog box.
  7. Using the first drop-down list for Condition 2, choose Cell Value Is.
  8. Using the second drop-down list for Condition 2, choose Equal To
  9. In the value box for Condition 2, enter 0. (See Figure 2.)
  10. Figure 2. The Conditional Formatting dialog box after setting two conditions.

  11. Click the Format button for Condition 2. Excel displays the Format Cells dialog box.
  12. Use the controls in the dialog box to modify the formatting, as desired.
  13. Click OK to close the Format Cells dialog box.
  14. Click OK to close the Conditional Formatting dialog box. The formatting is applied to the range of cells you selected in step 1.

Another solution is to combine your two conditions into a single condition. Follow these steps:

  1. Select the range you want conditionally formatted. (For this example, I'll assume that you've selected the range A2:A99.)
  2. Choose Conditional Formatting from the Format menu. Excel displays the Conditional Formatting dialog box.
  3. Using the first drop-down list for Condition 1, choose Formula Is.
  4. In the formula box for Condition 1, enter the formula =AND(A2=0,A2<>"").
  5. Click the Format button for Condition 1. Excel displays the Format Cells dialog box.
  6. Use the controls in the dialog box to modify the formatting, as desired.
  7. Click OK to close the Format Cells dialog box.
  8. Click OK to close the Conditional Formatting dialog box. The formatting is applied to the range of cells you selected in step 1.

The formula used in step 4 checks to make sure that the value is 0 and that the cell is not blank. The AND function makes sure that only when both criteria are satisfied will the formula return True and the format be applied.

There are any number of other formulas that could also be used. For instance, each of the following formulas could be substituted in either step 5 or 4:

  • =AND(COUNT(A2)=1,A2=0)
  • =AND(A2=0,NOT(ISBLANK(A2)))
  • =AND(A2=0,LEN(A2)>0)
  • =NOT(ISBLANK(A2))*(A2=0)

If you wanted an even faster way to highlight zero values while ignoring blanks, you might consider using a macro. The macro would be faster because you could just import and run it; you don't have to select a range of cells and enter the formula (or formulas) for the conditional formatting. The following macro is an example of one you could use:

Sub FormatRed()
    TotalRows = 65000
    ColNum = 1

    For i = 1 To Cells(TotalRows, ColNum).End(xlUp).Row
        Cells(i, ColNum).Interior.ColorIndex = xlAutomatic
        If IsNumeric(Cells(i, ColNum).Value) Then
            If Cells(i, ColNum).Value = 0 Then
                Cells(i, ColNum).Interior.ColorIndex = 3
            End If
        End If
    Next
End Sub

The macro checks the cells in column A. (It checks the cells in rows 1 through 65,000; you can modify this, if desired.) If the cell contains a numeric value and that value is zero, then the cell is filled with red. If the cell contains something else, then the cell is set back to its normal color.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2980) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Conditional Formats that Distinguish Blanks and Zeroes.

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

Store Common Addresses in AutoText Entries

Do you write letters to lots of different people? One good place to keep those addresses is in AutoText entries. They are ...

Discover More

ExcelTips Ribbon 2013 Archive (Table of Contents)

ExcelTips is a weekly newsletter that provides tips on how to effectively use Microsoft's best-selling spreadsheet ...

Discover More

Inserting Rows

As you are developing a spreadsheet, you'll often have the need to insert additional rows into your data. Sheets makes ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (menu)

Using Multiple Test Conditions

When creating conditional formats, you are not limited to only one condition. You can create up to three conditions, all ...

Discover More

Shading a Cell Until Something is Entered

Conditional formatting provides the opportunity to get very creative with your formatting. One such creative urge can be ...

Discover More

Removing Conditional Formats, but Not the Effects

Conditional formatting is very powerful, but at some point you may want to make the formatting "unconditional." In other ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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 2 + 4?

2017-03-15 16:18:18

Ozlem Eva Davis

You are amazing. Thank you very much. This saved me a ton of time.


2016-12-14 20:20:09

Marcelo

Hi mr. Waytt, I am trying to find out how to keep cells out from contitional formatting, even if they have formulas inside there.

I mean, I have a range that I made for to know when I have some payments to get.

They can find the right dates by a sum the date of the purchase and 30 days, 60 days, 90 days (each one in different columns, of course).

The conditional formatting makes the cell that have a date bigger then TODAY() to turn green fill.

The problem is that all empty cells inside that range now are green, too.

They have the formula, but no date to be showed.

Could you give me some hando to get rido of that, please?


2015-07-17 21:08:37

Phil Briggs

I have used Conditional format (bottom 1) in several sheets in rows that have data, and it works fine. But when I try to conditional format a row containing formulas, only the TOP or MAX works, not the MIN or bottom formulas. I have tried ignoring blanks, zeros etc, but nothing works. Does anyone know why? I have used it with formulas in one other workbook and it worked fine. What could be causing the problem?


2015-02-04 10:20:01

Patricia Fryer

I'm trying to fill any blank cell with " - ". I see that conditional formatting can shade a cell, but can it add text or numbering to any cell left blank?

Thanks!


2014-11-12 03:06:40

thankingu

you are a champ, thanks


2014-09-10 19:09:33

aleks.konjevic@gsahs.health.nsw.gov.au

This tip answered my need. I had the formula =ISBLANK(A2)=TRUE. This did not work, taking the TRUE out works.
Thanks


This Site

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

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.