In this article, you will find two quick ways to change the background color of cells based on value in Excel 2016, 2013 and 2010. Also, you will learn how to use Excel formulas to change the color of blank cells or cells with formula errors.
Everyone knows that changing the background color of a single cell or a range of data in Excel is easy as clicking the Fill color button . But what if you want to change the background color of all cells with a certain value? Moreover, what if you want the background color to change automatically along with the cell value's changes? Further in this article you will find answers to these questions and learn a couple of useful tips that will help you choose the right method for each particular task.
How to change a cell's color based on value in Excel dynamically
The background color will change dependent on the cell's value.
Task: You have a table or range of data, and you want to change the background color of cells based on cell values. Also, you want the color to change dynamically reflecting the data changes.
Solution: You need to use Excel conditional formatting to highlight the values greater than X, less than Y or between X and Y.
Suppose you have a list of gasoline prices in different states and you want the prices greater than USD 3.7 to be of the color red and equal to or less than USD 3.45 to be of the color green.
Note: The screenshots for this example were captured in Excel 2010, however the buttons, dialogs and settings are the same or nearly the same in Excel 2016 and Excel 2013.
Okay, here is what you do step-by-step:
- Select the table or range where you want to change the background color of cells. In this example, we've selected $B$2:$H$10 (the column names and the first column listing the state names are excluded from the selection).
- Navigate to the Home tab, Styles group, and choose Conditional Formatting > New Rule….
- In the New Formatting Rule dialog box, select "Format only cells that contain" under "Select a Rule Type" box in the upper part of the dialog box.
- In the lower part of the dialog box under "Format Only Cells with section", set the rule conditions. We choose to format only cells with a Cell Value - greater than - 3.7, as you can see in the screenshot below.
Then click the Format… button to choose what background color to apply when the above condition is met.
- In the Format Cells dialog box, switch to the Fill tab and select the color of your choice, the reddish color in our case, and click OK.
- Now you are back to the New Formatting Rule window and the preview of your format changes is displayed in the Preview box. If everything is Okay, click the OK button.
The result of your formatting will look similar to this:
Since we need to apply one more condition, i.e. change the background of cells with values equal to or less than 3.45 to the green color, click the New Rule button again and repeat steps 3 - 6 setting the required condition. Here is the Preview of our second conditional formatting rule:
When you are done, click the OK button. What you have now is a nicely formatted table that lets you see the highest and lowest gas prices across different states at a glance. Lucky they are in Texas :)
Tip: You can use the same method to change the font color based on the cell's value. To do this, simply switch to the Font tab in the Format Cells dialog box that we discussed in step 5 and choose your preferred font color.
How to permanently change a cell's color based on its current value
Once set, the background color will not change no matter how the cell's contents might change in the future.
Task: You want to color a cell based on its current value and wish the background color to remain the same even when the cell value's changes.
Solution: Find all cells with a certain value or values using Excel's Find All function or Select Special Cells add-in, and then change the format of found cells using the Format Cells feature.
This is one of those rare tasks that are not covered in Excel help files, forums and blogs and for which there is no straightforward solution. And this is understandable, because this task is not typical. And still, if you need to change the background color of cells statically i.e. once and forever unless you change it manually again, proceed with the following steps.
Find and select all cells that meet a certain condition
There may be several possible scenarios depending on what kind of values you are looking for.
If you need to color cells with a particular value, e.g. 50, 100 or 3.4, go to the Home tab, Editing group, and click Find Select > Find….
Enter the needed values and click the Find All button.
Tip: Click the Options button in the right-hand part of the Find and Replace dialog to get a number of advanced search options, such as "Match Case" and "Match entire cell content". You can use wildcard characters, such as an asterisk (*) to find any string of characters or a question mark (?) to find any single character.
In our previous example, if we needed to find all gas prices between 3.7 and 3.799, we would specify the following search criteria:
Now select any of the found items in the lower part of the Find and Replace dialog window by clicking on it and then press Ctrl + A to select all found entries. After that click the Close button.
This is how you select all cells with a certain value(s) using the Find All function in Excel.
However, what we actually need is to find all gas prices higher than 3.7 and regrettably Excel's Find and Replace dialog does not allow for such things.
Luckily, there is another tool that can handle such complex conditions. The Select Special Cells add-in lets you find all values in a specified range, e.g. between -1 and 45, get the maximum / minimum value in a column, row or range, find cells by font color, fill color and much more.
You click the Select by Value button on the ribbon and then specify your search criteria on the add-in's pane, in our example we are looking for values greater than 3.7. Click the Select button and in a second you will have a result like this:
If you are interested to try the Select Special Cells add-in, you can download an evaluation version here.
Change the background color of selected cells using "Format Cells" dialog
Now that all cells with a specified value or values are selected (either by using Excel's Find and Replace or Select Special Cells add-in) what is left for you to do is force the background color of selected cells to change when a value changes.
Open the Format Cells dialog by pressing Ctrl + 1 (you can also right click any of selected cells and choose "Format Cells…" from the pop-up menu, or go to Home tab > Cells group > Format > Format Cells…) and make all format changes you want. We will choose to change the background color in orange this time, just for a change :)
If you want to alter the background color only without any other format changes, then you can simply click the Fill color button and choose the color to your liking.
Here is the result of our format changes in Excel:
Unlike the previous technique with conditional formatting, the background color set in this way will never change again without your notice, no matter how the values change.
Change background color for special cells (blanks, with formula errors)
Like in the previous example, you can change the background color of special cells in two ways, dynamically and statically.
Use Excel formula to change background color of special cells
A cell's color will change automatically based on the cell's value.
This method provides a solution that you will most likely need in 99% of cases, i.e. the background color of cells will change according to the conditions you set.
We are going to use the gas prices table again as an example, but this time a couple of more states are included and some cells are empty. See how you can detect those blank cells and change their background color.
- On the Home tab, in the Styles group, click Conditional Formatting > New Rule… (see step 2 of How to dynamically change a cell color based on value for step-by-step guidance).
- In the "New Formatting Rule" dialog, select the option "Use a formula to determine which cells to format". Then enter one of the following formulas in the "Format values where this formula is true" field:
- =IsBlank()- to change the background color of blank cells.
- =IsError() - to change the background color of cells with formulas that return errors.
Since we are interested in changing the color of empty cells, enter the formula =IsBlank(), then place the cursor between parentheses and click the Collapse Dialog button in the right-hand part of the window to select a range of cells, or you can type the range manually, e.g.
=IsBlank(B2:H12)
. - Click the Format… button and choose the needed background color on the Fill tab (for detailed instructions, see step 5 of "How to dynamically change a cell color based on value") and then click OK.
The preview of your conditional formatting rule will look similar to this:
- If you are happy with the color, click the OK button and you'll see the changes immediately applied to your table.
Change the background color of special cells statically
Once changed, the background color will remain the same, regardless of the cell values' changes.
If you want to change the color of blank cells or cells with formula errors permanently, follow this way.
- Select your table or a range and press F5 to open the "Go To" dialog, and then click the "Special…" button.
- In the "Go to Special" dialog box, check the Blanks radio button to select all empty cells.
If you want to highlight cells containing formulas with errors, choose Formulas > Errors. As you can see in the screenshot above, a handful of other options are available to you.
- And finally, change the background of selected cells, or make any other format customizations using the "Format Cells" dialog as described in Changing the background of selected cells.
Just remember that formatting changes made in this way will persist even if your blank cells get filled with data or formula errors are corrected. Of course, it's hard to imagine off the top of the head why someone may want to have it this way, may be just for historical purposes :)
How to get most of Excel and make challenging tasks easy
As an active user of Microsoft Excel, you know that it has plenty of features. Some of them we know and love, others are a complete mystery for an average user and various blogs, including this one, are trying to shed at least some light on them. But! There are a few very common tasks that all of us have to perform daily and Excel simply does not provide any features or tools to automate them or make an inch easier.
For example, if you need to check 2 worksheets for duplicates or merge rows from single or different spreadsheets, it would take a bunch of arcane formulas or macros and still there is no guarantee you would get the accurate results.
That was the reason why a team of our best Excel developers designed and created 70+ add-ins that we call the Ultimate Suite for Excel. These smart tools handle the most grueling, painstaking and error-prone tasks in Excel and ensure quickly, neatly and flawless results. Below is a short list of just some of the tasks the add-ins can help you with:
- Remove duplicates and find unique values
- Merge tables and combine data from different sources
- Combine duplicate rows into one
- Merge cells, rows and columns
- Find and replacing in all data, in all workbooks
- Generate random numbers, passwords and custom lists
- And much, much more.
Just try these add-ins and you will see that your Excel productivity will increase up to 50%, at the very least!
That's all for now. In my next article we will continue to explore this topic further and you will see how you can quickly change the background color of a row based on a cell value. Hope to see you on our blog next week!
426 comments
thanks it has been helpfull
Hi Svetlana,
I am trying to set up a database for training records of employees,
using your rule above is it possible to set a cell to change green, yellow or red based on the training course expiry length.
For example Cell E13 is Green, if the date in cell F13 is 60 days away from the course expiry date set in G13 then Cell E13 turns yellow, if it passes the date then it turns red
Any help is much appreciated
Thanks
Craig
Hi Craig,
Try creating a rule for cell E13 with the following formulas:
Red: =$F13>$G13
Yellow: =AND($G13-$F13>0, $G13-$F13<=60)
Green: =$G13-$F13>=60
If you need to highlight more than 1 cell in column E, select them all before creating a rule and replace "13" in the above formulas with the number of the top row in the selection.
thx for help XD
Thanks a lot
it was so helpful for me
Can you use this to change a cells color based on a word in the cell instead of a value?
Hi,
Is there a way to select a random cell in excel and have all the other cell with the same value highlight? So, once I select another cell, the originla highlight is lost and all the cells with values same as the new selected cell gets highlighted.
I need this for work to make my presentation look spot on and set me apart from the rest. If you could reply back, I would very much appreciate it.
Thank you!
Shweta
Svetlana,
Thank you for your post. It is very useful. You seem to be an expert in excel color and I wonder if I can ask you a question about Excel color. I inherited an excel file with a pale yellow/sand color. When I check the color index, it shows -4142. When I change the color of the cell, it shows the normal color. When I set as no fill, I get this color (-4142). When I print the sheet, the color displays similarly as a no filled cell. I wonder if you know how this -4142 "color" gets set in the first place?
Thank you in advance.
Hello Tina,
I am hesitant to give any advice without seeing the formatting. If you can send us your workbook at support@ablebits.com, we will hopefully be able to help.
Thank you very much
Hi Svetlana,
I am very impressed with the creative solutions I have seen on this page.
I am hoping you can help me with a problem I have been struggling with for months.
I would like to copy the contents and format of a column of cells and paste them in another column using a formula.
All columns are formatted as type = General
Column A is a list of random IP addresses that are color formatted as green or red cells. Just say every other IP address is green and the others red.
Column C is also a list of IP addresses (a master list) with no color.
In column B, I want to take all the IP addresses in column A and line them up on the same row as the IP address in column C (and keep the color formatting from column A).
In column B to get the IP address from column A to line up with the IP addresses in column C, I used the formula:
=IF(ISNA(MATCH(C1,A:A,0)),"",INDEX(A:A,MATCH(C1,A:A,0)))
This works but column B does not have the color formatting as the cells in column A
Is there any way to keep that formatting when using a formula?
Here is the data (remove column B if you want to check the formual):
192.168.36.21 192.168.36.21 192.168.36.21
192.168.32.31 192.168.33.174
192.168.35.0 192.168.32.31 192.168.32.31
192.168.37.56 192.168.40.163
192.168.45.10 192.168.42.82
192.168.43.221 192.168.35.0 192.168.35.0
192.168.45.108 192.168.37.56 192.168.37.56
192.168.46.208 192.168.38.105
192.168.32.226 192.168.38.214
192.168.39.208 192.168.43.224
192.168.32.246 192.168.45.10 192.168.45.10
192.168.35.109 192.168.43.221 192.168.43.221
192.168.34.99 192.168.46.215
192.168.32.55 192.168.45.108 192.168.45.108
192.168.46.208 192.168.46.208
192.168.32.226 192.168.32.226
192.168.43.42
192.168.39.208 192.168.39.208
192.168.32.246 192.168.32.246
192.168.34.23
192.168.36.68
192.168.35.109 192.168.35.109
192.168.34.99 192.168.34.99
192.168.32.55 192.168.32.55
Maybe this is not the right approach and using some other way like Offset would be the way to go. Any input is welcome
Thank You for your valuable time,
Sven
Found the answer from you here:
https://www.ablebits.com/office-addins-blog/excel-conditional-formatting-formulas/#blanks-nonblanks
Thank you so much, and welcome to the top of my bookmarks list =)
Thank you, Thomas! Much appreciated : )
Hello,
I'm trying to set up a sheet where if I enter something in A (will be a number) then B,C,D,E turns red until something is entered into each one.
Once a value, or word is entered in each of B:E they turn back to white.
Is this possible? It seems like trying to connect 2 formulas may be contradicting
I am partially red/green colour blind and rely on the labels that appear when I use Fill on the Home ribbon (pause over a colour and the label appears). But those labels do not appear when I use Fill from the conditional formatting feature. How do I get them to appear when using conditional formatting? Also how do I get labels to appear in 'more colours'?
Hello Kevin,
I am very sorry, I don't know a way to make the labels to appear for conditional formatting colors.
Hi Svetlana
I have a range of values in Row1 - say A1 to J1
I have another range of values in row2 - say A1 to J2.
I am comparing A1 and A2; then B1 with B2....... then J1 to J2.
Whenever value in row1 < row 2, the row2 cell should be changed to red color.
This is needed to be done across the entire row 2.
Kindly let me know the solution.
Hello Sridhar,
If you have to highlight each cell in row 2 that has a value greater than the value in row 1 in the same column, then select row 2 and create a rule with this formula:
=A2>A1
If you have to highlight the entire row 2 if at least 1 cell in row 1 has the value less than in row 2, you need a helper cell, e.g. A5, with the following array formula (remember to press CTRL+Shift+Enter instead of Enter to complete it):
=SUM(--(A1:J1<A2:J2))
After that, select row 2 and create a rule with this formula:
=$A$5>1
Thank you Svetlana!!
Hi,
I have applied conditional formatting to change the color of few cells to red in a row based on a value. After applying conditional formatting,if i copy and paste some data to these cells, the background color changes to white. Can you please help?
Hello Satish,
When you use the standard Paste command, the current rules are replaced with the ones applied to inserted cells.
You need to use the Paste Special option instead: right-click on the destination cells, select Paste Special from the context menu and choose the Values or Formulas radio button under Paste.
Thank you so much, it is very useful!
I also want to create legend after doing these way, how to create leagend?
Thank you indvance!
I am tracking training of people on my project. All of the training they take has to be retaken annually.
Based on the completion date in a cell I want to turn the cell GREEN if the number of days fall within 1 to 334 days from the completion date. I want to turn the cell YELLOW If the number of days fall within 335 to 364 days from the completion date. I want to turn the cell RED if the number of days is 365 or more from the completion date.
In col. B2- 100. In col.A3-101,A4-102,A5-103. In col.C3-99,C4-98,C5-97.
when col.B2 there are 101 i want green color in A3.
when col.B2 there are 102 i want green color in A4.
when col.B2 there are 103 i want green color in A5
& Viseversa
when col.B2 there are 99 i want red color in C3
when col.B2 there are 98 i want red color in C4
when col.B2 there are 97 i want red color in C5
i want to color some selected cells based on cell color
please let me how to do it
Thanks
i want to color selected cell based on cell color
hi the post is very helpful to me bcoz I have learnt a new thing but I got one question how do you do if you want to color the cell after entering the value maybe less than 3 to color yellow and greater than 3 or empty cell to remain with default color