by Alexander Trifuntov, updated on
In this post, we'll take a closer look at conditional formatting in Google Sheets and learn the quickest and most effective ways of setting it up. We'll consider several examples to see how to create conditional formatting with one or several conditions, and how to color cells or change font color by custom criteria. We'll pay particular attention to conditional formatting based on other cells.
Why do we need conditional formatting in a table? Isn't it easier to format cells manually?
Highlighting particular data with color is a great way to draw attention to the records. Many of us do this all the time. If cell values meet our conditions, e.g. they are greater or less than some value, they are the greatest or the smallest, or perhaps they contain certain characters or words, then we find such cells and change their font, font color, or background color.
Wouldn't it be great if such changes to formatting occurred automatically and drew yet more attention to such cells? We would save a lot of time.
This is where conditional formatting comes in handy. Google Sheets can do this work for us, all we need is to explain what we want to get. Let's look at some examples together and see how simple and effective it is.
Suppose we have chocolate sales data in our table. Each row in the table contains an order we got from a particular customer. We used drop-down lists in column G to specify if it was completed.
What can be interesting for us to see here? First, we can highlight those orders that exceed $200 in total sales. We have these records in column F, so we'll use our mouse to select the range of values with the order amount: F2:F22.
Then find the Format menu item and click on Conditional formatting.
To begin with, let's consider Google Sheets conditional formatting using a single color.
Click Format cells if..., select the option "Greater than or equal to" in the drop-down list that you see, and enter "200" in the field below. This means that within the range we selected, all cells with values that are greater than or equal to 200 will be highlighted using the format we set right at the same place: bold red font in the yellow background.
We can see our formatting rule applied right away: all the necessary cells changed their appearance.
You have the choice of setting up conditional formatting not only with one hue but using a color scale. To do this, select Color scale in the conditional format rules sidebar and use ready sets of color. You can also pick hues for the minimum and maximum points, as well as for the midpoint if necessary.
Here we created a color scale where the cells get lighter as the order amount gets smaller, and darker as the sum increases.
If the color scale seems too bright to you, you can create several conditions under the "Single color" tab and specify a format for each condition separately. To do this, click "Add another rule".
Let's highlight the orders that are over $200 in Total sales, and those that are under $100.
As you can see, we have two formatting conditions here. The first one is for values that are greater than 200, the second one concerns values that are less than 100.
Tip. You can add as many conditional formatting rules in Google Sheets as you need. To delete it, just point to it and click the Remove icon.
The suggested list of the conditions that we can apply to our data range is quite vast. However, it may still not be enough. Sooner or later you will need to create a condition that can't be described using the standard means.
That's why Google Sheets provide the possibility to enter your own formula as a condition. This formula lets you describe your requirements using standard functions and operators. In other words, the result of the formula must be either "True" or "False".
Use the last item in the drop-down list to enter your formula: "Custom formula is".
Let's see how it works.
Say we want to know which among our orders were made during the weekend. None of the standard conditions works for us.
We will select the range of dates in A2:A22, go to the Format menu and click Conditional formatting. Select the "Custom formula is" item in the "Format cells if" drop-down list and enter the logical formula that will help us identify the day of the week by the date.
If the number is greater than 5, then it's Saturday or Sunday. In this case, the formatting we set below will be applied to the cell.
As you can see, all weekends are highlighted with color now.
Here is another example. Let's bring out the orders for dark chocolate with the help of a different format. We follow the same steps to do this: select the data range with the types of chocolate (D2:D22) and use the following condition:
This function will return "True" if the name of the chocolate type contains the word "Dark".
Look what we got: the orders for Dark Chocolate as well as for Extra Dark Chocolate became emphasized. No need to look through hundreds of rows to find them now.
If we want to format text values, then the standard "Text contains" condition is essential.
You can use special wildcard characters to add some flexibility to the search condition.
Tip. Wildcard characters can be used in the "Text contains" and "Text does not contain" fields as well as in your custom formulas.
There are two most commonly used characters: the question sign (?) and an asterisk (*).
The question sign corresponds to any single character. For example, as you can see in the screenshot, the text rule that contains "??d" formats cells with such values as "Red", but not such as "Dark".
"??d" means that letter "d" should come third from the beginning of the word.
Use an asterisk to omit zero to any number of characters. For example, a rule that contains "*d*" should format both cells: with "Red" as well as with "Dark" values.
For the question and asterisk characters not to be perceived as wildcard characters in your text values, a tilde (~) is usually added before them. E.g. the text rule that contains "Re?" in our example formats the cells with "Red", while the rule with "Re~?" won't find any cells as it will be looking for the value "Re?".
In the examples we described above, we applied conditional formatting to certain cells of a column. Perhaps you thought: "It would be so nice if we could apply this to the whole table!". And you can!
Let's try to highlight any unfulfilled orders with a special color. To do this, we need to use the formatting condition for the data in column G where we specified if the order was completed, and we shall format the entire table.
Note. Please note that we applied formatting to the entire table A1:G22.
Then we used our custom formula where we specified that:
Tip. You need to use the dollar sign ($) before the name of the column. This creates an absolute reference to it, so the formula will always refer to this particular column, while the row number can change.
In other words, we ask it to move down within the column starting with the first row and look for all cells with the value "No".
As you can see, not only the cells that we checked for our condition became formatted. Conditional formatting is now applied to entire rows.
So, let's remember 3 basic rules to conditionally format rows in a table:
We often hear the question "How do we apply conditional formatting and make it easy to change the condition?" This is not difficult at all.
Just use your own formula with a reference to the cell where you specify the necessary condition.
Let's go back to our sample data with the orders for chocolate in Google Sheets. Suppose we are interested in the orders with fewer than 50 and more than 100 items. We'll go ahead and enter these conditions in column H next to our table.
Now we shall create conditional formatting rules for the table of orders.
We set the range to format to "A2:G22" to keep the table header as it is.
Then we follow the steps you know and use our formula.
Here is how conditional formatting formula for the orders with over 100 items looks:
Note. Please note that you need to use absolute references ($) when using cells outside the table.
A dollar sign before the column name means the absolute reference to the column. If the dollar sign is before the row number, then the absolute reference goes for the row. For more info, please check out this detailed discussion of cell references.
$H$3 in our example means an absolute reference to the cell, i.e. whatever you do with the table, the formula will still refer to this cell.
Note. We need to use an absolute reference to column E and an absolute reference to cell H3 where we have our limit of 100. If we don't do this, the formula won't work!
Now let's add the second condition to highlight the orders with fewer than 50 items. Click "Add another rule" and add another condition just like we did for the first one.
Please see the formula we use in our conditional formatting rule:
The largest and the smallest orders are now highlighted with color. The task is accomplished. However, it's not nice that we got extra numbers in our sheet, which may be confusing and ruin the way the table looks.
Placing auxiliary data in a separate sheet would be a better way to go. I will describe it in more detail in my next post when we learn how to create drop-down lists.
Let's switch to sheet 2 and enter these new conditions there.
Now we can create conditional formatting rules for the table of orders by referring to these limits.
Here is where we may face an issue. If we simply use the address of the cell from sheet 2 in the formula, we'll get an error.
Note. Direct cell references in the formulas for conditional formatting are possible only from the current sheet.
So, what shall we do now? The INDIRECT function will help. It lets you get the cell reference by writing its address as text. Here is how the cell reference within a conditional formatting formula will look like:
Here is the second formula:
As a result, we get the same outcome as before, but our sheet is not cluttered with additional records.
Now we can change formatting conditions without updating the rule settings. It's enough to simply change the records in the cells, and you get a new table.
We have learned how to apply conditional formatting rules by using numeric data from a certain cell. What if we want to base our condition on a cell with text? Let's see how we can do this together.
We'll try to find the orders for dark chocolate:
In cell G5 of Sheet 2, we enter our condition: "Dark".
Then we return to Sheet 1 with the table and select the range to format again: A2:G22.
Then we select Format menu, pick Conditional formatting, and enter the following formula into the Custom formula is field:
Tip. Remember that you need to enter absolute references to the range you need to check for the word "Dark" (D2:D22).
The function INDIRECT("2!$G$5") enables us to get the value from cell G5 of Sheet2, i.e. the word "Dark".
Thus, we have highlighted the orders that have the word from cell G5 of Sheet 2 as a part of the product name.
We could make it easier, of course. Our formula would look this way:
However, in case we wanted to find a different product, we would have to edit the conditional formatting rule. This takes a little longer than simply updating the value in cell G5.
You may certainly need to remove all conditional formats from your table.
To do this, first, select the range of cells where you have conditional formatting applied.
You will see all the rules that you created in the sidebar.
Point your mouse to the condition that needs to be deleted and click the "Remove" icon. Conditional formatting will be cleared.
If you don't remember the exact cell range you formatted, or if you want to get rid of formats as quickly as possible, then select the cell range and go to the Format menu - Clear formatting. You can also use the combination of keys Ctrl + \.
Note. Remember that not only conditional formatting, but all other formats used in your table will be cleared in this case.
We hope that applying conditional formatting in Google Sheets will simplify your work and make the results more graphic.
Table of contents