
Tips.Net > ExcelTips Home > Formatting > Conditional Formatting > Conditional Formats that Distinguish Blanks and Zeroes
Summary: Conditional formatting is a great boon to Excel users. One use is that you can use it to highlight cells that contain zero values. However, if a cell is blank, Excel also considers that cell to be equal to zero. This tip explains how you should perform your conditional test to get only those cells containing an actual zero value. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)
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 test. The following steps can implement the two-condition approach:
Another solution is to combine your two conditions into a single condition. Follow these steps:
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 step 4:
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.
Tip #2980 applies to Microsoft Excel versions: 97 2000 2002 2003
Tame Your Data! ExcelTips: Filters and Filtering provides all the details necessary to let you manage large sets of data with confidence and ease. Its information-packed pages demonstrate how to use the two types of filters provided by Excel: AutoFilters and advanced filters.
Check out ExcelTips: Filters and Filtering today!
If you have tons of data to analyze, one of the best tools in Excel's arsenal is the PivotTable. Learn how to use this tool to analyze your data. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site