For all general questions relating to Excel but not including VBA. 'if' statement to change the color or style of a font in an excel document? The Font object has many properties like the Color property and the Bold property. Color property To change the color of an Excel range, use the Font property of the Range object, and then the Color property of the Font object.
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. The background color will change automatically when the cell value changes. Once set, the background color will not change no matter how the cell's value changes.
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 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 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.
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 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. Click the Format button and choose the needed background color on the Fill tab (for detailed instructions, see 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.
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 the 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. 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 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 60+ add-ins that we call the.
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:. And much, much more. Just give these add-ins a try (a fully-functional trial version is ) and you will see that your usual Excel routines will take only a fraction of time they formerly did and your productivity will increase up to 50%, at the very least!
If you like any of these tools, be sure to make use of the coupon code that we provide especially for our blog readers: AB14-BlogSpo It will give you the 15% discount on the Ultimate Suite or any separate product. 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. Hope to see you on our blog next week! You may also be interested in:. Hi there, So my situation is kind of similar, but different. I am trying to change the formatting (color) of a number of cells in an array (4 cells in a row) given a value that I am going to input in 1 of those cells.
This input will be compared to an array of values already input. So depending on the value of the cell I am inputting, if it is lesser than my base I want it to be compared to, the row will be come green. Or stay white.
This is the rule formula I was thinking about, but can't find better. =IF($C10+$D10=125, $AF$5 (cell to be compared to), IF($C10+$D10=150, $AG$5, IF($C10+$D10=225, $AF$6, IF($C10+$D10=250, $AG$6, IF($C10+$D10=275, $AH$6, FALSE))))) And, it does not work. It doesn't adapt dynamically.
Any thoughts? I would like some help please with conditional formatting. We have an inventory sheet that indicates the items and number of items in the store. I have used the Less than function in the conditional formatting to define a change in background colour when and item numbers is reduced below a certain amount.
This amount is variable for each item. We have encountered the problem that when new items are added to the inventory and then they are sorted alphabetically, then the conditional formatting stays at the cell position and is not linked to the items number, such that now the formatting applies to a different item with different limits.
How can I resolve this? Is there a way to link the conditional formatting to a item rather than a cell? Many thanks in advance for your help. Hi, I am working on some Demand and Supply data, where you have the Demand value in,say, cell C3 and Supply value in cell D3. I need to colour background both cells to the same colour for three possible scenarios,i.e. Cell C3 is greater than cell D3 then both cells to have a background colour of amber. Also,if cell D3 is greater than cell C3 then both cells to come up red and finally, if both cells equal each other then both cells come up green.
I would then need to format all other cells in the spreadsheet.i.e. Cells C3 and D3 represent week 1, the next cells, E3 and F3 would represent week 2 and so on.
Each line represents a different entity so would need to format the cells down as well as across. Sometimes the value of one of the cells can be zero and I need to ensure this also comes up with the same background colour as the cell it i sbeing measured against. I have tried the conditional formatting but all the cells kept coming up red! Many thanks for your help.
Kind Regards Nick.
I Have built a string using a formula in excel. As an example Cell C3 contains text 'Languages' Cell C4 = 'English, Spanish,German, French' My Forumla = C3 & ':' & CHAR(10) & C4 The Desired text would be: Languages: English, Spanish, German, French (where the bold text would actually be some color like red) Is there a way to do this in Excel (change partial text formatting). I Have tried a formula.
(Not working) Function formatText(InText As Range) 'Set font color InText.Characters(1.5).Font.Color = Red 'InText.Characters((InStr(1, ':', InText) + 1), (Len(InText) - InStr(1, ':', InText))).Font.ColorIndex = 3 End Function. Regarding Hightower's question, 'how would you cast a formula output to a string so that you can apply the text formatting?'
To 'cast' the output of a formula so that you can apply text formatting, you must write the value returned by the formula into the spreadsheet, then apply the formatting to the value you wrote. You could either write the value into the cell containing the formula (which will erase the formula), or you could write the value into a different place in the spreadsheet (which will preserve the formula but then you'll be seeing double). Sub CellFormat(InText as Range) InText.formula = cstr(InText.value) ' converts result of formula into a string literal 'or: InText.offset(0,1).formula = cstr(InText.value) - writes the value in the cell next to InText InText.characters(1, 5).font.color = vbRed End Sub Then CellFormat range('$A$1') will replace the formula in cell $A$1 with a string constant and change the color of the first five characters to red.
If you want to do this for a range larger than one cell, add this code to the above: Sub RangeFormat(InText as Range) For each c in InText CellFormat(c) Next End Sub.