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. The entire sheet or selected cells change color instead of only the supposed impacted row.
    I am selecting exactly as mentioning on the tutorial.
    Is someone having the same issue?

    • Hi! I think that you are doing something that is different from what is described in the user guide. Describe in more detail what you are doing and what is the conditional formatting formula that you are using.

      • I actually did as described in the tutorial.

        In a tab, I made a column called Status with a dropdown picking status from another tab called DATA
        I'd like my line to change to green when the cell in column L to change to DONE
        It works when I do it on one line, but when copying the conditional formatting to my entire sheet, it colours the entire sheet to green.

        • More precision: when I select DONE on the Conditional formatting line I made the rule for, it colours the entire sheet green instead of copying the conditional formatting to each line separately.
          I'd like to avoid creating a separate conditional formatting rule for each line of my sheet.

          • Hi! Instead of applying a conditional formatting rule to a single cell, create a conditional formatting rule for a range of cells.
            For example, apply rule =$L2="DONE" to range A2:Z100.
            To do this, first select the range of cells that you want to apply and then create a conditional formatting rule. It will apply to the whole range, not just one cell.

            • Yes, that's what I did but it colours the entire cell within range A2 to Z100 in green.
              Actually I figured out there are $ signs in my formulas and I can't remove them. When I apply the conditional formatting, Excel adds them again. Might be why I am stuck.
              Any tips on how to avoid excel adding $ everywhere ?

            • Exemple:
              In applies to:
              I enter =A45:L45
              When i click apply, Excel re write =$A$45:$L$45

              • When you specify a conditional formatting range, it is normal. Make sure that the mixed reference is correctly written in the conditional formatting formula.

              • My formula is correct since it works on the applied line.
                But it needs to be recreated, and isn't independent line per line.
                I can't find comments online with similar issues, so seems like I am the only one having this issue on Office 365?

              • I gave you an example of a conditional formatting formula to apply to a range of cells. But I can't see what you're actually doing. You will find all the information you need in the article above and in the recommended articles.

  2. Thank you very much,it useful

  3. This was enormously helpful. Very clear and covered all the bases.

  4. i want to have the rows grade colored based of the value of a cell on that row

  5. Did the biz for me. Thanks for the clear and well illustrated instructions.

  6. also should be =$G1>0 and for the other rule =$G1<0

  7. It doesn't work at all
    My goal is to set one bacround color for every row where colum G is less than zero
    And another color when column G is greater than zero
    So I've create two rules
    ="$G0"
    I want to apply the rules on the whole sheet : I dont know how to do it appearently the rules only exists on one row
    And there is no result at all
    I'm a C# developper but totally stupid with excell
    Thanks if someone can help me

    • select the whole sheet before setting up the rule

    • Hi! If you read the instructions in the first paragraph of this article carefully, first select the cells (or the entire worksheet) where you want to change the color by condition. Then create a conditional formatting rule.

  8. I am trying to set it up so that when I input text into a certain column it changes the whole row to a certain color. For example, I have 2 columns that i need this for. One column is "APPROVED" and the other is "DELIVERED". For the APPROVED column when i input the text for who approved it (name) and the date i need that whole row to change to a certain color. For the DELIVERED column when i input the date i need it to change to a different color than the APPROVED column. I hope that makes sense.

  9. thx for ur sharing

  10. thanks for sharing

  11. Hello,

    I would like the row in my spreadsheet to change colors once a date has been added to the "Date Complete" column. I have tried using =CELL("format",$D2)="D1" type formula, but have found that since I have formatted the cells in column D, the entire spreadsheet changes color. How can I get the row to change color if there is a date in the column, and not change color if there is no date in the column?

  12. Hi, I'm trying to set up colours for a particular 'status letter' which is in Column E, to colour cells/rows from columns A to E. For example, the letter 'P' in cell 2E, I want cells on row 2 from A2 - E2, to be a light blue; Then the following letters, still in column E, to have the same formatting, but a different colour. F is green, C is red, B is orange & R to have the font changed to red.

    I'm having trouble searching for an answer with your examples above.
    Can you help please.

    thanks.

    • IT'S OK. Pls disregard. I worked it out. thanks.

  13. I'm trying to have rows turn grey if the customer enquiring is outside of our coverage area (multiple post codes) so can it do it saying if the cell doesn't contain NR or IP it turns the whole row grey?

  14. Hello!
    I am trying to create a Gantt style chart to track the progress of some upcoming projects and it has been requested that the actual completion date be a different color based on where it falls in the 'allowable timeframe'.

    The below formula adds a corresponding filled cell in the calendar side but I am only able to figure out how to do it in one color. I would like to be able to do it in Green, Amber and Red based on how it falls in comparison to the completed date.
    =AND(Actual_Completion_Date4>=M$9,Actual_Completion_Date4<N$9)

    I have scoured online and would consider myself to have a pretty decent knowledge of Excel, I am coming up blank on this solution. I am not opposed to have multiple formulas in order to get the different colors.

    ANY assistance you may be able to provide would be greatly appreciated!

  15. Hello,

    Is there a particular formula that allows me to have the whole row turn a color (grey for my purposes) if any text is entered in a particular box? I understand the conditional formatting process but want the line to be greyed out automatically when any date is entered into my "DATE CLOSED" box.

    Thanks,
    Lauren

  16. Could you please share the video

  17. On the Spreadsheet I'm making I'm trying to make an entire row change based on whether one cell says "Resolved" or "Not Resolved", I have used the Formula described above, =$B2="Resolved" and =$B2="Not Resolved" Which then Applies to =$A$2:$J$2 but only the cell where the text is Written is colored the rest stay blank

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