Explanation
Note: Excel contains many built-in “presets” for highlighting values with conditional formatting, including a preset to highlight cells that equal a specific value. However, for more flexibility, you can use your own formula, as explained in this article.
If you want to highlight cells that equal a specific value, you can use a simple formula that returns TRUE when the condition is met. For example, to highlight any cells in the range C5-C11 that contain the text “dog”, you can use conditional formatting with this formula:
=C5="Dog"
In the example shown we have placed the value we are looking for in cell F6, so it can be easily changed. The conditional formatting rule itself is using this formula:
=C5=$F$6
This formula is just a simple comparison using the equal to operator (=).
When you use a formula to apply conditional formatting, the formula is evaluated relative to the active cell in the selection at the time the rule is created. In this case, the rule is evaluated for each of the 7 cells in C5:C11, and during evaluation C5 (entered as a relative reference ) will change to the address of the cell being evaluated in the range where conditional formatting is applied.
The address of the cell that contains the search string (F6) is an absolute reference ($F$6) so that it is “locked” and won’t change as the formula is evaluated.
Case sensitive option
By default a comparison is not case-sensitive. If you need to check case as well, you can use the EXACT function like this:
=EXACT(C5,$F$6)
Explanation
In this example, the goal is to highlight differences in two ranges, B2:B11 and C2:C11, using conditional formatting. To do this, we need to create a new conditional formatting rule, triggered by a formula, like this:
- Select the range B2:C11, starting at cell B2.
- Select Home > Conditional Formatting > New Rule
- Select “Use a formula to determine which cells to format”
- Enter the formula =$B2<>$C2 in the input area
- Set the desired format to highlight differences
- Save the rule
When you use a formula to apply conditional formatting, the formula is evaluated relative to the active cell in the selection at the time the rule is created. In this case, the rule is evaluated for each of the 20 cells in the two columns of data.
The references to $B2 and $C2 are " mixed references " - the column is locked, but the row is relative. This means only the row number will change as the formula is evaluated. Whenever two values in a row are not equal, the formula returns TRUE and the conditional formatting is applied.
A case-sensitive option
Note that the “equals to” (=) and “not equals to” (<>) operators are not case-sensitive. If you need a case-sensitive comparison, you can use the EXACT function with NOT, like so:
=NOT(EXACT($B2,$C2))
EXACT performs a case-sensitive comparison and returns TRUE when values match. The NOT function reverses this logic so that the formula returns TRUE only when the values don’t match.
Another approach
One problem with this approach is that if there is an extra or missing value in one column, or if the data is not sorted, many rows will be highlighted as different. Another approach is to count instances that appear in one range but do not appear in another. For details on this approach, see highlight missing values .