How to change the row color based on a cell value in Excel

Learn how to quickly highlight the entire row based on a single cell's value in Excel. Tips and formula examples for number and text values.

Last week we discussed how to change the background color of a cell based on its value. In this article you will learn how to highlight entire rows in Excel based on a value of one cell, and also find a few tips and formula examples that will work with numerical and text cell values.

How to change a row color based on a number in a single cell

Say, you have a table of your company orders like this: Source data - a table of the company's orders

You may want to shade the rows in different colors based on the cell value in the Qty. column to see the most important orders at a glance. This can be easily done using Excel Conditional Formatting.

  1. Start with selecting the cells the background color of which you want to change.
  2. Create a new formatting rule by clicking Conditional Formatting > New Rule… on the Home tab. On the Home tab, click Conditional Formatting > New Rule…
  3. In the "New Formatting Rule" dialog window that opens, choose the option "Use a formula to determine which cells to format" and enter the following formula in the "Format values where this formula is true" field to highlight orders with Qty. larger than 4:

    =$C2>4 Open the 'New Formatting Rule' dialog and enter the needed formula.

    And naturally, you can use the less than (<) and equal to (=) operators to find and highlight rows that have Qty. smaller than 4 or equal to 4:

    =$C2<4

    =$C2=4

    Also, pay attention to the dollar sign $ before the cell's address - it is needed to keep the column letter the same when the formula gets copied across the row. Actually, it is what does the trick and applies formatting to the whole row based on a value in a given cell.

  4. Click the "Format…" button and switch to Fill tab to choose the background color. If the default colors do not suffice, click the "More Colors…" button to pick the one to your liking, and then click OK twice. Click the 'More Colors…' button to choose the color to your liking.

    You can also use any other formatting options, such as the font color or cells border on the other tabs of the Format Cells dialog.

  5. The preview of your formatting rule will look similar to this: The preview of your formatting rule
  6. If this is how you wanted it and you are happy with the color, click OK to see your new formatting in effect.

    Now, if the value in the Qty. column is greater than 4, the entire rows in your Excel table will turn blue. Highlight entire rows based on a cell value.

As you can see, changing the row's color based on a number in a single cell is pretty easy in Excel. Further on, you will find more formula examples and a couple of tips for more complex scenarios.

How to apply several rules with the priority you need

In the previous example, you may want to highlight the rows with different values in the Qty. column in different colors. For example, you can add a rule to shade the rows with quantity 10 or greater. In this case, use this formula:

=$C2>9

After your second formatting rule is created, set the rules priority so that both of your rules will work.

  1. On the Home tab, in the Styles group, click Conditional Formatting > Manage Rules… .
  2. Choose "This worksheet" in the "Show formatting rules for" field. If you want to manage the rules that apply to your current selection only, choose "Current Selection".
  3. Select the formatting rule you want to be applied first and move it to the top of the list using the arrows. The result should resemble this: Use the up and down arrows to set the rules' priority.

    Click the OK button and the corresponding rows will immediately change their background color based on the cell values that you specified in both formulas. The entire rows colored based on two conditional formatting rules

How to change a row color based on a text value in a cell

In our sample table, to make follow-up on orders easier, you can shade the rows based on the values in the Delivery column, so that:

  • If an order is "Due in X Days", the background color of such rows will turn orange;
  • If an item is "Delivered", the entire row will be colored in green;
  • If an order is "Past Due", the row will turn red.

Naturally, the row color will change if the order status gets updated.

While the formula from our first example could work for "Delivered" and "Past Due"(=$E2="Delivered" and =$E2="Past Due"), the task sounds a bit trickier for "Due in…" orders. As you see, different orders are due in 1, 3, 5 or more days and the above formula won't work because it is purposed for exact match.

In this case, you'd better use the SEARCH function that works for the partial match as well:

=SEARCH("Due in", $E2)>0

In the formula, E2 is the address of the cell that you want to base your formatting on, the dollar sign ($) is used to lock the column coordinate, and >0 means that the formatting will be applied if the specified text ("Due in" in our case) is found in any position in the cell.

Create three such rules following the steps from the first example, and you will have the below table, as the result: The rows' color is changed based on a text value in a cell.

Highlight row if cell starts with specific text

Using >0 in the above formula means that the row will be colored no matter where the specified text is located in the key cell. For example, the Delivery column (F) may contain the text "Urgent, Due in 6 Hours", and this row will be colored as well.

To change the row color when the key cell starts with a particular value, use =1 in the formula, e.g.:

=SEARCH("Due in", $E2)=1

in this case, the row will only be highlighted if the specified text is found in the first position in the cell.

For this conditional formatting rule to work correctly, make sure there are no leading spaces in the key column, otherwise you might rack your brain trying to figure out why the formula does not work :) You can use this free tool to find and remove leading and trailing spaces in your worksheets - Trim Spaces tool for Excel.

How to change a cell's color based on a value of another cell

In fact, this is simply a variation of changing the background color of a row case. But instead of the whole table, you select a column or a range where you want to highlight rows and use the formulas described above.

For example, we could create three such rules to shade only the cells in the "Order number" column based on another cell value (values in the Delivery column). Changing a cell's color based on a value in another cell

Highlight rows based on several conditions

If you want to shade the rows in the same color based on several values, then instead of creating several formatting rules you can use the OR or AND functions to set several conditions.

For example, we can color the orders due in 1 and 3 days in the reddish color, and those that are due in 5 and 7 days in the yellow color. The formulas are as follow:

=OR($F2="Due in 1 Days", $F2="Due in 3 Days")

=OR($F2="Due in 5 Days", $F2="Due in 7 Days") Use the =OR formula to change a row's color based on several conditions.

And you can use the AND function, say, to change the background color of rows with Qty. equal to or greater than 5 and equal to or less than 10:

=AND($D2>=5, $D2<=10) An example of using the =AND formula

Naturally, you are not limited to using only 2 conditions in such formulas, you are free to use as many as you need. For example:

=OR($F2="Due in 1 Days", $F2="Due in 3 Days", $F2="Due in 5 Days")

Tip: Now that you know how to color cells to differentiate between various types of values, you may want to know how many cells are highlighted in a certain color and calculate the sum of values in those cells. The good news is that you can automate this too and you will find the solution in this article: How to count, sum and filter cells by color in Excel.

These are only a few of many possible ways to zebra stripe your Excel worksheets based on a cell's value that will respond to change of data in that cell. If you need something different for your data set, drop us a comment and we will try to figure this out.

546 comments

  1. Hello Sevtlana,

    I saved an excel sheet from the "searchmyfiles" app. It's an inquiry for duplicate file names on all my drives. I've sorted them by duplication number which range from 1 to over 1000 files that have duplicates. I have some files that have been duplicated up to 10 times. I'd like to highlight every other duplication number (NOT every other row). Can you help me with that, please?

  2. I have a financial sheet that I use, once the check has cleared the bank I highlight the cell. I am trying to figure out the format that will change the total in the summed cell when I highlight the payees cell but not change the value (amount) within the cell (once highlighted the value becomes zero, but leaves the amount in the cell), reflecting the amount that was paid, but affecting the end state balance.

  3. Old formula is
    =sumifs('m.16-1'

  4. I want fill colour in cell by formula, but I have different sheet of issue from and final report sheet separator in another sheet but I one worksheet
    And I have all ready one formula in.final report sheet.
    So help me how I can make formula

  5. 1.Customer 2.Description 3.Status 4.Del Date 5.Billing date 6.Order Val 7.Comments

    Hi

    Points 1-7 are my coloumns. I want to apply a rule whereby the status on each specific row will change the colour of more than one cell in that row (2,3,4,5,6), like for instance, if job complete the row should turn green.
    However my limitation at the moment is that I can only apply this one row at a time whereas I need a rule that can apply to the specified rows...

    I hope that I am making sense.

  6. Hi, I am formatting our worksheet and each values must change color depending on it, so I was wondering how to apply the conditional formatting on over 2000 rows.

  7. Hi,
    I am trying to make a planning with excel.

    I have set up the following conditional formatting:

    =AND($D$3>=$B$4;$D$3=$B$4;$E$3<=$C$4)

    I don't want to set up this rule for every single cell so I will have 200 rules eventually.

    Is there a way to dynamically applie this one rule to all the necessary cells? like doing with the value of some cells if you want to quickly fill those cells. Then you can just fill in 2 values and pull the values across the necessary cells and Excel will automatically fill in the right values.

  8. Thank you Svetlana and everyone. Your Q&A have helped me in learning more about Excel.

  9. Hi, I hope you can assist. I am needing something like this done in a VBA macro.

    I am using both 2007 and 2010 version of MS Office Excel.

    Problem: Store POS does not have Low Inventory Report built in (free/cheap version). We download a CSV file with 3 fields: Item, Category and Balance. We then manually add 3 more fields: Previous Balance, Quantity Received and Quantity Sold. The CSV is then filtered to copy only items we still carry to a new workbook (old items can not deleted from the POS Inventory). A macro is used to separate items based on category name to different worksheets.

    We have over 100 different categories, each category has a different number of items. Item Name (Column A) cell is colored based on Quantity on Hand and Number Sold. If Quantity on hand = 0, cell is Red, If Quantity on hand = 1 or 2, cell is colored yellow; if Sold = 1 - 3 then cell is colored Blue and if Sold is higher than 3 then the cell is Green. If The Quantity is 0-2 AND the Sold is 1 or higher, then the text will be bold and colored the Sold colors (Blue or Green) while the cell is still filled with the On Hand Colors (Red or Yellow).

    Doing the conditional formatting manually for every worksheet takes me a couple hours. Is it possible to use a VBA macro to do all worksheets for all conditioning? If you can show the script to get me started, I would appreciate it. I can do a script for a single worksheet when the range (number of rows) is known and also for a single condition. If possible, 1 macro to do all worksheets (total number of worksheets can change) and more than one condition.

  10. Hi I need to use this example but it wont work for me. Im using it to look at the status of work so i have 4 statuses complete, active, Not Confirmed and Cancelled. I want to change each row colour when i change the status of the job. I have tried your example as per above highlighting all my area so its highlighted from A6:P31 then created a new rule with the formula =SEARCH("Active",$F$6)=0 it works but changes every row on the sheet. I want it to just change that one row? what am i doing wrong? Row F wil always be my status bar and i have about 100 rows of work im looking at?

    Hope you can help.

    Elaine

  11. Hello - I'm trying to use conditional formatting to check row by row within a range (A:G) for any blank cells. If there is a blank cell in the range I want to highlight the cell for that specific row in column A red. I want formula / conditional formatting to be able to do this for each row through the entire spreadsheet.

    Example for Row 2: If cell C2 is blank within range A2:G2, I want to highlight cell A2 red.

    Any help would be greatly appreciated.

  12. Thanks, SEARCH helped solve my problem statement.

  13. Hi, I need help with excel.

    I have database of my daily work tasks which includes dates in one column and in the other columns I have other datas that are mostly in text. Now I need an excel code/function that can provide a "summary of tasks" that I did by each date listed and a respective count of how many tasks were completed on that specific dates. For example if only 10-december, I have 4 entries of work and on 11th-december, I had 14 then the excel should count and prepare a summary of my work like this

    Summary of Work

    Dates Tasks Completed

    10-december 4
    11-december 14

    If somebody can prepare a format or a code and post it, I would really appreciate it. Please note, the excel code should also reflect any changes I make on the dates or counts. For example, if I find that the date was incorrect and I change it to 12-december, the summary should reflect that right away.
    thank you.

  14. I want colored two different values with two different colors which is in one cell. How I can?

  15. I have a rather large worksheet with workorders that need to be completed. For each workorder a specific skillcode is recquired. On a daily basis, I have a set amount of available hours for production. I've added a column that adds the amount of workorders that can be completed on a day until I've hit the maximum for that day. In the following cell it starts to calculate again.

    Example: I have 60 hours available, and in column D I have the amount of hours per workorder. Column E has an if statement that says when the hours in D have hit 60 hours, start the calculation from the start: E19 = 59.2 hours -> E20= 6 (the required time for this new workorder). I want to format the worksheet in such a way that each time it starts the calculation again, a different color is used (E2:E19 = blue, then E20:26 = red and so on). Can you perhaps help me out on this?

  16. Oh my goodness! Do you know how long I was trying to figure this out??? Thank you so much... The help function in Excel did not help me and I'm pretty good with Excel...SMH...Thank you!

  17. Hi!

    Not sure if this will make sense but I NEED HELP!! I have a list of 60 names and their leave. When a cell is populated I need it to turn yellow, when it goes over 15% of the column being populated I want it to turn Red.

    I think this is possible with Conditional Formatting but I can't seem to get it to work. Obviously I might be way out but I have created the formula at the bottom of the column so I have one rule to say the cell is less than 64 turn it yellow then a second rule that says if it is greater than 64 turn the cell red. It just doesn't colour any cell.

    Is there anything you can help with?

  18. Hello Svetlana,

    I would like to format a cell color based on two other cells meeting certain conditional formats. To be specific I have a cell (G16) that will be highlighted in a color based on the value in that cell not being between the values in C117 and D117. I have a second cell (H16) that will be highlighted if the calculated value in that cell is not between C118 and D118.
    If the conditions in both G16 and H16 are met, then I want to highlight cell I16 in a second color. Is there a way to do this?

  19. Hello,

    Is there anyway to highlight a row based on a cell value that's on another sheet in the same workbook?

    for instance, cell B7 in Sheet1 contains a decimal value (in this case, it is 5). And the condition is, highlight the range A2:B6 in Sheet 2. But the cell B7 in Sheet1 is dynamic. Hence if i enter 7, the range A2:B8 in sheet 2 must be highlighted.

    Is this achievable through conditional formatting?

  20. Hello,

    I have created a live-spreadsheet for Orders with 'Date Required' and 'ETA' columns in them.

    I would like the dates in the 'ETA' to be highlighted if they are greater than the dates stated in the 'Date Required' column.

    I can get this to work on individual Rows through Conditional Formatting but cannot repeat the process on a large scale through-out the entire sheet.

    Please let me know if you can help.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)