How to apply conditional formatting if two cells are not equal

To apply conditional formatting if two cells are not equal, select the two cells and then click on the “Conditional Formatting” button in the Home tab of the ribbon. Select “New Rule” and choose “Use a formula to determine which cells to format”. Enter a formula that checks if the two cells are not equal and then select the formatting options you want to apply to the cells. Click “OK” to apply the formatting.


Often you may want to apply conditional formatting to two cells in Excel if their values are not equal.

The following example shows exactly how to do so.

Example: Conditional Formatting if Two Cells Are Not Equal

Suppose we have the following lists in Excel that contain the names of 10 students each:

Suppose we would like to highlight the rows where the two names are not equal between the classes.

To do so, highlight the values in the range A2:B11, then click the Conditional Formatting icon on the Home tab, then click New Rule:

In the new window that appears, click Use a formula to determine which cells to format, then type in the following formula into the box:

=$A2 <> $B2

Then click the Format button and choose a fill color to use, then click OK:

Each row where the names are not equal will automatically be highlighted:

Note that this formula is case-insensitive. This means if we have “john” in one column and “John” in the other, the formula will assume these values are equal.

However, you can use the following formula to apply a case-sensitive search:

=NOT(EXACT($A2,$B2))

Excel: Apply Conditional Formatting if Cell Contains Text

x