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. I have three columns ("Invoice Inc. VAT", "Credit Inc. VAT" and "Balance Inc. VAT").
    I would like to have the values in the "Balance Inc. VAT" column to be displayed in red when the other two columns ("Invoice Inc. VAT" and "Credit Inc. VAT") are not equal.
    When the values in the "Invoice Inc. VAT" and the "Credit Inc. VAT" columns are equal, I would like the values in the "Balance Inc. VAT" column to be displayed in black.
    I have tried two Conditional Formatting rules (one for "Less Than" and one for "Equal To") but all the values in the "Balance Inc. VAT" column just show red.
    Pleas can you help?

  2. I have three tabs, one (Definition Tab) having definitions like Small, Medium, Large, & X Large and Time to complete work for each size in weeks are 3, 4, 6 and 8 respectively. The second tab (Forecast Tab)has weeks in columns starting week 1 till week 53 of an year and 4 Rows as Small, Medium, Large and X Large. The third tab (Customer Tab) has customer name, Size, resource name, work start week, delay if any, total weeks as columns and each row represent different customers.

    I want to have the rows in second tab (Forecast Tab) highlighted with colors. For eg: if size of a customer is Large (6 Weeks), work start week column is having value 8, & delay if any has value 3, 9 (6+3) columns against a newly added row in forecast tab need to be highlighted with Yellow automatically. Like wise, any input modification done to the customer tab, based on definitions, the forecast tab should get a row added under the weeks accordingly.

    Appreciate your help is getting this using Excel 2010 or above.

    thanks in advance.
    Krish

  3. I want to change the font color of cells if the Status is "NO REPLY". How will I do that?
    CUSTOMER NAME PRODUCTS PIC STATUS
    ABC 123 JOHN NO REPLY
    DEF 456 MIKE PLACED AN ORDER

  4. I Need help from u
    i wants color to colum in 1-10 then after 10-20colum i needed to give another color how can i?

  5. I have two columns with dates. I have shaded the first column with some specific dates. I want to shade same dates in the second columns with the help of some formulas.

  6. Thank you

  7. Hi,

    I use excel to create daily reports for my team. It involves copying data from an internal site and pasting it into excel so i can manipulate it and make it useful for us. The problem is the data comes with links (which I need). This ruins any conditional formatting I may have on the template used to create the reports.

    Is it possible to keep the source formatting and have text in a single cell change the color of a row?

  8. HI, i have data in two column in one excel sheet, now in another sheet i am linking the same data by clicking + sign. But Data is linking but the problem is: when i changed cell color in one sheet its not changing in another excel sheet particularly for that cells only

    pl help

  9. Peoples i need help as i suck with excel.

    I would like a row to be highlighted if there is nothing in the last two cells of that row. However there would be data in each of the other cells in said row.

  10. Hi Svetlana,
    there are two things GOOD & BAD (say 2 ROWS)
    I want a formula that will make "BAD" row Backgroud RED in color and NO COLOR IF GOOD
    So Is it possible that certain formula for colors exist?
    Regards,
    Savinn

  11. Apologies. The formatting formula we are using is "$C2>0", cheers. Z

  12. Dear Sir,

    This is a very valuable post. I learned a lot from it.

    I was wondering if there is a way to change the color of a cell "Only" when the value of the sell change from a certain value to another, without changing other cells that got same value under the same formula.

    I will try to explain better: I have "Stock" column which has only one of two values in its celle: either "0" or "10".

    Items that are out of stock have value of "0" while any other item that is in stock (or comes back to stock) get value updated to "10" because we never re-stock items less than 10 units minimum in quantity.

    My issue is not by having items becoming out of stock because we have a control on this. The issue is that some items come back to stock but we never notice early, therefore we miss the chance to increase the quantity as the quantity will remain zero in the marketplaces we are selling our items on.

    With your code, I was able to use formula "$C2<0", however, it changes to color to all items that we have "10" in quantity, regardless whether they were already having "10" or got updated from zero to ten, making your formatting formula not very beneficial to me.

    Is there a way to highlight only the cells that specifically get values updated from zero to ten without affecting the cells that already got value of "10" in first place?

    I look forward to hearing from you or anyone else who has the knowledge of dealing with this matter.

    Best regards,
    Zed Sefi

  13. I am using the following formula that I pieced together after some research online. It seems to be working in the example I tried it on, but I don't fully understand the entire formula. I want to interpret so I can figure out whether or not it will work for similar checks and balances. The formula and reason are as follows:
    =AND(ISBLANK($D5)=FALSE,NOT(ISNUMBER(MATCH($D5,$E5,0))))

    Looking for a cond format that will fill column D if its respective C cell is not the same value/text (d1="x" and c1=""), but will not fill is column d is blank, d and c are blank, and d and c match.

    Can you help interpret the formula and if it will work for an entire spreadsheet comparing 2 columns (separate conditional formats)?

  14. Hi Svetlana

    Not from want of trying, I have failed to have a colour of a row changed from red to green if column F has a number in it

    On another sheet I would like to mark the whole row as green if the number in column R is greater than 65.

    Please help

    Darcy

  15. How to change automatically the text color based on a cell's matched text in Excel

  16. pleas sand me condition formatting function.
    IF
    AND
    IF(AAAA,)AND)

  17. Hi
    If I want to highlight any cell in the column that contains a number larger than the previous one in the same column, what should I do?

    • Hello, Gloria,

      Please try the following:
      Go to Conditional Formatting -> New Rule -> Use a formula to determine which cells to format
      Enter the following formula:
      =AND(ROW(A1) <> 1, A1>OFFSET(A1, -1, 0))

      Hope this helps.

      • Hello Maria

        Thank you for your above explanation.

        My predicament is the same as Gloria's "If I want to highlight any cell in the column that contains a number larger than the previous one in the same column, what should I do?"
        I have tried your formula and I cannot seem to get it to highlight the cell.
        In the example below, I would like to see -11.41 and +3.09 highlighted, because in both instances the cell above it, is >10 value points away from it.

        -33.22
        -26.75
        -22.19
        -11.41
        -8.21
        +3.09
        +8.03

        What would my formula be? To make it easier for me to work with, the nominated cell numbers are:-
        -11.41 is H51
        and
        +3.09 is H53

        I hope I am making sense :)
        Many thanks

        David

  18. Is it possible to use conditional formatting to put a coloured border underneath a row where the date in column A changes.

    So if you had a table with:
    14-01-16
    14-01-16
    15-01-16
    16-01-16
    It would put a different coloured border under each different (unique) date.

  19. Hi
    I want to color my a row which contain "E" in a cell of that row.
    please provide me a solution for my problem

  20. I want to colour my employee id numbers with red and green which is randomly upto 1200 numbers anybodycan you help me to make conditional format on this

    • Hello Rathna!

      Please use the Home Tab -> Condition Formatting -> Color Scales command

      You can use the "More Color Scale Rules" additional command to define a custom "2-Color Scale" format style.

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