Excel formula to alter cell's background color but keep its current value?
You didn't tag with your Excel version or provide any sample data, so let's say you are using Excel 2007 or greater, and your worksheet looks like this:
To compare the cells in column D
to the corresponding cells in column A
, do the following:
- Select cells
D2:D7
by clicking on cellD2
and then dragging down to cellD7
, so that cellD2
is the Active Cell (as seen in the above screenshot) - On the Ribbon, click
Home -> Conditional Formatting -> New Rule...
- In the Select a Rule Type section of the New Formatting Rule dialog, click Use a formula to determine which cells to format
- In the Format values where this formula is true textbox, enter the following formula:
=D2<>A2
- Click the Format button
- In the Format Cells dialog, set your desired formatting (e.g. click the Fill tab, and select the Yellow color)
- Click the OK button
- In the New Formatting Rule dialog, click the OK button
- Repeat the above steps, except select cells
E2:E7
, and use the formula=E2<>B2
Note:
Since the columns I am formatting are contiguous, I could have simply selected cells D2:E7
instead of D2:D7
, and then skipped step 9
. However, I am assuming that the columns you want to format are not necessarily contiguous.
Optional:
Since background-color formatting hides cell gridlines, one additional thing I like to do in the Format Cells dialog is to click the Border tab, select "White, Background 1, Darker 15%" in the Color dropdown, and then apply that color to the Outline borders. That way, your formatted cells will appear to retain their gridlines.
Result: