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. Hi,
    I want to colour my bar chart "bars" based on the text written inside the bar chart "bars". ( ie if "A" is written in first bar- the bar colour should turn to red, if "B", then blue and so on), the text in the bar is dynamic and changes with the data.
    Can you please advise.
    Thanks
    Sam

      • Thanks Fedor.
        Actually I want the different "bars" within Bar chart to change colour automatically based on "Text" written within the "Bars".
        ie if the text entered in the "Bar" is North, the "Bar" colour should be filled with "yellow" colour, and so on.
        Thanks again.

  2. Hi,

    1-3,7-9,13-15 till last row how can change "Bold" in VBA
    4-6,10-12,16-18 till last row how can change "Italic" in VBA

    Please give me suggestions.

  3. Hi, I am trying to conditionally format cells in one column based on overdue dates in another column. Specifically, I want cells in column A to turn red if the date in column P (corresponding row) is past due. When I set my conditional formatting for column A, this is the formula I have inputted: =$P2=TODAY . I also want to set up a second rule for due dates 90 days out, where the corresponding row in A turns blue. This is the formula I have inputted for this conditional format: =$P2<TODAY+90 . Neither format is working however, so I know I'm doing something wrong. Can you point me in the right direction? Thank you!

  4. Hi There, Can someone please help me with a conditional formatting to change a whole line colour based upon whether its Saturday or Sunday.

    I am using =E12+1 where E12 is a date 01/01/16 to have my cell look like this Saturday, 2 January 2016

    I had supposed using =SEARCH("Saturday",$E13)>0 to change the whole line but obviously the formula for dating does not contain "Saturday"

  5. You have saved Preston. Thank you.

  6. Hello All,

    i am facing one issue:

    suppose in a row, there is one box with green color.

    what formula should i use for this to know that in row we have different color?

  7. Hi,
    I am trying to conditionally format a row which is reference another cell.
    EX - IF A1 is some number like(1/2/3/4) & B1 is YES/NO.
    if in A1(1)=B1(No) then A1 become condition by color & if Yes another color.
    Help

  8. What formula would I use, if I want the text of a row to be red if one particular cell is blank and another is not blank in said row.

  9. Hi Svetlana,
    I am trying to conditionally format a row of numbers based on a manually entered number in cell c4 my data is from cell A11 to I39 for ex if I enter a random number between 10 & 24 in cell C4 I would like the corresponding row to be a different color, I have managed to do this but it will only format the FIXED numbers from A11 to A39. Thanks in advance for any help you can give me its driving me crazy..

  10. I'm trying to make a cell match the color of another cell. I want A2 to match K2 (which is a date) the same color. K2 is formatted to change to red when it is 90 days out from today.

  11. Hi Svetlana,

    Im having some problem. Let say my table is as follow:

    A B C D E F G
    1 2 3 4 5
    6 7 8 9 10

    I want to change the cell's colour based on the other cell value, for example:

    A B
    1 DONE
    2 NOT
    3 DONE
    4 DONE
    5 DONE

    If the word in column B is 'done", the cell 1 in the upper table will turn blue, let say. How to do it? The sequence of the numbers in upper table also not in order. It involve a lot of numbers and im not able to do it cell by cell. Please help me..

  12. Hi Svetlana,

    thank ypu very much for your post. Really useful. I just have the problem that saving and reopening the file,it doesn't keep the conditional formatting set. Do you know whay it might be?

    Thank you very much in advance,
    Valeria

  13. I am trying out this example on my Excel 2013 and I get an error that "we found a problem with this formula.."
    I have defined a rule with the formula below:
    =OR($D2="Due in 1 days",$D2="Due in 7 days")

    • Hello Boniface,

      Most likely the problem is in a different List Separator. This formula is written with a comma, which is the default List Separator in North America and some other countries. In European countries the comma is reserved as the Decimal Symbol and the List Separator is set to semicolon. So, try replacing "," with ";" like this:

      =OR($D2="Due in 1 days";$D2="Due in 7 days")

  14. helo guys,

    I need a help on excel where i have 500 id numbers in duplicates. like

    Id subject grade
    1001 xxxx A
    1001 YYYY A
    1002 XXXX B
    1002 YYYY EX
    1001 ZZZZ B

    i have data like above. Here what I need is, want to highlight id column with different colors. Id should get same color even if i have duplicate data in workbook. Please help me out on this. Thanks in advance.

  15. helo guys,

    I need a help on excel where i have 500 id numbers in duplicates. like

    Id subject grade
    1001 xxxx

  16. Hi,
    I’m not sure if this is still open for questions but if so, I would really appreciate your help.
    In column A I have a list of sites. In column B I have a set of random dates which highlight the day in which these sites had been uploaded to the excel sheet. In columns C,D and E I have names (E.G C; John, D; David, E; Sam). These last three columns also have drop down menus with an option which needs to be selected for each site row. If any individual has not selected an option from the list when Column B had passed 5 days I need each of the name columns to turn orange. If the date passes 10 days I need the name cells for that row to turn RED. Is this possible with conditional formatting? I have seen this done previously but the sheet had been deleted so I am unable to copy formula. Can you please help?
    Thanks!

    • Hello Hannah,

      Can you please send me your sample workbook at support@ablebits.com and an example of the result you want to get?

  17. Hi Svetlana,
    I was looking for a way to visually separate rows by category with color, I have 1-3 rows in a row that can be the same category. As if I could control the banded color of a table based on a variable - So the best I came up with was identifying whether the variable was new or the same as the last row, so there is one variable that just says "New" or "Same". I am trying to get all the "New" rows one color and all the "Same" another color. I am having trouble with the formula to highlight the whole row based on cell text, it only wants to highlight the cell or it highlights every row. The formulas are =$E$2="New" and =$E$2="Same" applied it to the whole range but it doesn't work. Am I missing a step? Or is there a better way to visually separate by a variable for viewing purposes?

    Thanks!

  18. Hi Dear,

    Is there any way to highlight number of cells based on entering a number on first cell for instance; i enter number 10 and automatically it highlights 10 cells ahead?

    Thanking you in advance

  19. Hi Svetlana,

    I have an excel file which is shared between 4 people and conditional formatting doesnt work on a share file.
    What would you recommend?
    I want to change the color of a row from E4:G4 if the text value of Cell I4 is "Done".

    Thanks,

  20. My Online Teacher :)

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 :)