Written by Allen Wyatt (last updated September 6, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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:
Figure 1. The New Formatting Rule dialog box.
Another solution is to combine your two conditions into a single condition. Follow these steps:
Figure 2. The Format Cells dialog box.
The formula used in step 5 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 step 5:
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 = 5000 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 5,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:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7131) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Conditional Formats that Distinguish Blanks and Zeroes.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Sometimes you want whatever is displayed in one cell to control what is displayed in a different cell. This tip looks at ...
Discover MoreConditional formatting can be used to draw attention to all sorts of data based upon the criteria you specify. Here's how ...
Discover MoreConditional formatting can be used to highlight cells that contain the improper type of data for your needs. This tip ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-09-07 09:35:55
J. Woolley
For more on this subject, see https://www.ablebits.com/office-addins-blog/excel-conditional-formatting-blank-cells/
2022-09-06 10:15:14
Sharon
Great tip, Allen - thank you!
2021-02-04 18:09:56
AT
You are a legend!
2020-11-18 14:33:20
Johan Falk
Cool, never new I could distinguish blanks from zeros. Now my conditional formatting looks a lot better. Thank you! :)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments