There are several ways to color format cells in Excel, but not all of them accomplish the same thing. If you want to fill a cell with color based on a condition, you will need to use the Conditional Formatting feature.
Fill a cell with color based on a condition
Before learning to conditionally format cells with color, here is how you can add color to any cell in Excel.
Cell static format for colors
You can change the color of cells by going into the formatting of the cell and then go into the Fill section and then select the intended color to fill the cell.
In the above example, the color of cell E3 has been changed from No Fill to Blue color, and notice that the value in cell E3 is 6 and if we change the value in this cell from 6 to any other value the cell color will not change and it will always remain blue. What does this mean?
This means that cell color is independent of cell value, so no matter what value will be in E3 the cell color will always be blue. We can refer to this as static formatting of the cell E3.
Conditional formatting cell color based on cell value
Now, what if we want to change the cell color based on cell value? Suppose we want the color of cell E3 to change with the change of the value in it. Say, we want to color code the cell E3 as follows:
- 0-10 : We want the cell color to be Blue
- 11-20 : We want the cell color to be Red
- 21-30 : We want the cell color to be Yellow
- Any other value or Blank : No color or No Fill.
We can achieve this with the help of Conditional Formatting. On the Home tab, in the Style subgroup, click on Conditional Formatting→New Rule.
Note: Make sure the cell on which you want to apply conditional formatting is selected
Then select “Format only cells that contain,” then in the first drop down select “Cell Value” and in the second drop-down select “between” :
Then, on the first box, enter 0 and in the second box, enter 10, then click on the Format button and go to Fill Tab, select the blue color, click Ok and again click Ok. Now enter a value between 0 and 10 in cell E3 and you will see that cell color changes to blue and if there is any other value or no value then cell color revert to transparent.
Repeat the same process for 11-20 and 21-30 and you’ll see that number changes as per the value of the cell.
Conditional formatting with text
Similarly, we can do the same process for text values as well instead of numerical values by using the “Specific Text” in the first drop down and in the second drop-down select either of 4 values containing, not containing, beginning with, ending with and then enter the specific text in the text box.
For Example:
First, select the cell on which you want to apply conditional format, here we need to select cell B1. On the home tab, in the Styles subgroup, click on Conditional Formatting→New Rule.
Now select Format only cells that contain the option, then in the first drop down select “Specific Text” and in the second drop-down select either of the 4 options: containing, not containing, beginning with, ending with. In the example below, we use beginning with “J” and then select Format button to select Blue as the fill color.
Conditional format based on another cell value
In the example above, we are changing the cell color based on that cell value only, we can also change the cell color based on other cells value as well. Suppose we want to change the color of cell E3 based on the value in D3, to do that we have to use a formula in conditional formatting.
Now suppose if we want to change cell E3 color to blue if the D3 value is greater than 3 and to green if the D3 value is greater than 5 and to red, if D3’s value is greater than 10, we can do that with the conditional format using a formula.
Again follow the same procedure.
First, select the cell on which you want to apply conditional format, here we need to select cell E3. On the home tab, in the Styles subgroup, click on Conditional Formatting→New Rule.
Now select Use a formula to determine which cells to format option, and in the box type the formula: D3>5; then select Format button to select green as the fill color.
Keep in mind that we are changing the format of cell E3 based on cell D3 value, note that the cursor now is pointing at E3, which is the cell we use to set conditional format. The formula “=D3>5” means if D3 is greater than 5 then the value of E3 will change to green. Click ok and see the color of cell E3 changes to green as D3 right now contains 6.
Now let’s apply the conditional formatting to E3 if D3 is greater than 3. This means if D3>3 then cell color should become “Blue” and if D3>5 then cell color should remain green as we did it in the previous step.
Now, if you follow the above steps as we did for Green color, you will see that even if the cell value is 6, it is showing blue color and not green, because it takes the latest conditional formatting we set for that cell, and as 6 is also greater than 3 hence it is showing blue color but it should show green color.
So, we have to arrange the rules we have applied for any particular cells, we can do that by going into Manage Rules option of conditional formatting.
You can see all the rules applied to that cell and then we can arrange the rules or set their priority by using the arrow buttons. A number greater than 5 will also be greater than 3, hence greater than 5 rule will take higher priority and we can move it upward using the arrow buttons.
Now when you enter 6 in D3, the cell color of E3 will become green and when you enter 4, the cell color will become blue.
If you are tired of reading too many articles without finding your answer or need a real Expert to help you save hours of struggle, click on this link to enter your problem and get connected to a qualified Excel expert in a few seconds. You can share your file and an expert will create a solution for you on the spot during a 1:1 live chat session. Each session last less than 1 hour and the first session is free.
Are you still looking for help with Conditional Formatting? View our comprehensive round-up of Conditional Formatting tutorials here.
Home » Excel: How to change the background color based on the cell value
Especially for huge MS Excel tables, it is helpful to mark cells with colors, if they contain a certain value. This is possible by using the “If-function”. In this article we will show you how.
Changing the background color of Excel cells using the “If – function”
Time needed: 3 minutes.
The easiest way to explain how changing the colour of Excel cells via the if-function works is by using an example. So, let’s imagine you’re recording accounting transactions. To immediately spot negative values, you can highlight these cells using the if-function.
- Prepare a list
As a starting point, prepare a list of all your accounting transactions. Mark the cells you want to highlight with colors according to their value.
- Choose “Conditional formatting”
click on the tab named “Home” and find the button “Conditional formatting”.
- Select your formatting features
This function allows you to change colors of cells based on their value: You can choose between “Less than…”, “Greater than…”, “Between…” and many more options. For our example, we want to mark cells with a value less than zero with a red background color. Therefore, click on “Highlight cell rules” and “Less than”.
- Enter formatting conditions
Chose “0” in the field “Format cells that are less than” and decide for a formatting option. For our example “Light red fill with dark red text” is most appropriate.
- Confirm your selection
Click on “OK”. MS Excel will format the cells you marked in the beginning immediately.
- Check the result
Now you are able to see days with negative revenues quickly. You can repeat this procedure for other formatting options. For example, use the button “Between than” to highlight days with earnings high enough to meet your long-term business goals.
written by Corinna
November 4, 2021
Precise colours as a hint can be very helpful in extensive Excel tables. With the logic function “if-then” you can quickly provide the corresponding cells with event-dependent colours.
Change cell colour in Excel: Per if-function
In our example, we manage our stock with an Excel spreadsheet. As soon as an item falls below a predefined minimum stock level, the corresponding cell is to turn red via an if-function. The example was created with Microsoft Excel 2013.
- First we create a mini-table in which we enter some articles as well as the corresponding stock quantity.
- We then consider the respective minimum quantity for each item. If you want the same minimum stock to apply to several items, mark the corresponding cells all at once.
- After the preliminary work is done, select the tab “Start”.
- In the quick start bar, go to “Conditional formatting”.
- In the context menu “Conditional Formatting” decide on the first option “Rules for highlighting cells”.
- As we want to have a colour warning for an item understock, select the logic function “Smaller than”.
- In the “Smaller than” menu you now enter the value from which a certain reaction – i.e. a colour change of the cell – should take place (see screenshot).
- Finally, you just select a colour for the cell, the font or the cell border. You have a variety of marking options.
- In our example, we decide to use the signal colour red as soon as the number of brushes falls below 300.
- Feel free to experiment a little with the “Conditional Formatting”. The tool offers you a lot of options that are useful and, above all, very convenient and quick to use.
Set colours via if-functions: How to do it
In this example, we show you how to change cell colours using an if-function. Here you can use many other conditions besides “less than”, such as “greater than”, “between two values” or “equal to value”.
Related Articles
Leave a Comment
How to change the color of your cells in function of the value in your cells?
The secret to change the color? A logical test
To change the color with a formula, you MUST create a logical test.
A logical test returns TRUE or FALSE, or also 0 and 1. And it’s exactly what we need to create our own rule.
- The test returns TRUE, then we apply of custom format
- The test returns FALSE, the conditional formatting is not applied
For many people there is a confusion between a logical test and the IF function. The first argument of the IF function is the logical test and it’s just what we need.
Step 1: Test your rule before
I have seen a lot of mistake in my professional career when people wants to create their own rules. My advise is to test your rule in a cell.
For instance, you want to highlight all the cells with a value lower than 15.
So in column C, let’s write the test and see the result
=B2<15
Step 2: Copy your test as conditional formatting rules
- Select the cell where to apply the rule (here B2)
- Copy your formula with a basic copy-paste.
- Open the menu Home > Conditional Formatting > New Rule
- Select the rule type Use a formula to determine which cells to format
- In the text box, paste your test 😀
Step 3: Change the color
Once you have click on the button Format, you can change, the font, the background of the cell, the borders, ….
For instance here, we change only the color of the background when the test is TRUE.
Validate your rule to close the New Rule dialog box
Step 4: Apply the rule to many cells
At this step, the rule applies only for the cell B2. But now, we need to apply the same formula for the range B2:B9
- Open the menu Conditional Formatting > Manage Rules
- When the dialog box opens, you can see that the rule only applies on B2.
- Update this field to write the range of cells to apply the rule
- Now, all the cells where the rule is TRUE are red 😀👍😍
Other examples
Create your own rules to change the color is a very common task in Excel. Here is a list of other articles where we use the same technique.
- Compare 2 columns
- Highlight birthday
- Highlight week-end
- ….
Why it doesn’t work in my workbook 😱😱
One thing is very, very, VERY important is to selected the cell when you create your rule ❗❗❗
If you haven’t selected the correct cells when you have written or pasted your test, the rule applies in the wrong cell.
For instance, here, we have selected the cell B4 when we have pasted the test.
This is the only reason why you can have an issue between the result expected and the result you want 😉👍
Tutorial video
In this video, you will see 3 examples with 3 differente techniques
I’m using a formula to make decisions. I want to color a cell, a particular color, based on the decision of the formula. The problem is that the value of the cell does not reflect any pertinent information.
For example, i want to fill a bag with 10lb of oranges without going over. I have a number of bins filled with oranges of known weight. The formula then check the total weight against what is in the bin to see if it would exceed the weight.
bins; 7lb, 5lb, 2lb, 1lb.
Using these bins and an example; the first bin is 7lb which is less than 10lb and is added to the bag. Since 7lb is added to the bag the cell reflects the total weight in the bag and needs to be colored. The second bin is 5lb and if added to the bag would exceed 10lb so it not added. The cell continues to reflect 7lb because nothing was added and no color is needed. The third bin is 2lb and when added to the bag would not exceed 10lb. The cell then reflects the total in the bag of 9lb and needs colored. Finally the last cell is 1lb and if added to the bag would not exceed 10lb. The cell then reflects the total in the bag of 10lb and needs to be colored.
Here is an example of what i mean. The colomn on the left show what bins are available. The following colomns show different desired combonations. The cell that corresponds to the bin that is added is colored green.
Conditional formatting won’t work because the cells don’t show pertinent information that can be compared to something. The formula that made the decision on whether to add to the total or not should make the decision.
Is there a way to color the cell depending on what the IF statement decided?