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.

88 comments

  1. I am trying to make a spreadsheet change color in each row when a cell text changes, because I need to report any change I make to the spreadsheet with a yellow color, and sometimes I forget it :)

  2. 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?

  3. 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?

  4. 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!

  5. 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

    1. Hi!
      I have not been able to replicate your problem. Apply the =$B2="Resolved" rule to the range =$A$2:$J$2 or =$A$2:$J$10

  6. Hello,
    Is it possible to create a formula to number cells, but only the ones, which have one color (e.g. only white ones)?
    + make formula automatically 'refresh' when we decide to change the color of one or two more rows?

    KR,
    Natalia

    1. Hello!
      You can get the cell color in Excel using the user-defined function GetCellColor.
      To numbering cells with a specific color in column A, you can use something like this formula starting from cell B2

      =IF(COUNT($B$1:B1)=SUM(--("#"&DEC2HEX(GetCellColor($A$2:A2))="#FFFFFF")), "", SUM(--("#"&DEC2HEX(GetCellColor($A$2:A2))="#FFFFFF")))

      I hope it’ll be helpful.

  7. Hello There,

    I own a food product business. I Have a worksheet where I keep track of deliveries. In the worksheet, against each item, I record Delivery Status(Column K) and Payment Status (Column L). My requirement is two fold.

    Rule 1. When Item is delivered, but payment is yet to be received from customer, I want the row colour to change to yellow based on the text "y" in Column K. In this case, corresponding cell in Column K is Blank.

    Rule 2. When Payment is received from customer, , I want the row colour to change to green based on the text "y" in Column L. In this case, Column L as well as Column L contain the text "y".

    Rule 2 should be applied by overpowering Rule 1.

    I am able to set up the rules individually, but I am not yet able to make rule 2 being able to overpower rule 1.

    Thanks in advance for your advice.

    Regards,
    Rucha Mulay

  8. I want to use conditional format to set the background color for each cell in the B column based on the data in the O Column.

    My formula: Formula=$O$2="Cancelled" Format (black color) Applies to =$B$2
    Formula =$O$2="Delivered" Format Blue color Applies to $B$2.

    I want to be able to select all the cells in Column O and Column B and have the colors change. But this doesn't work. I have to set the 5 different options and type them for every cell.

  9. You wrote: "In the formula, E2 is the address of the cell that you want to base your formatting on, the dollar sign ($) is used to apply the formula to the entire row..."

    This is not entirely correct. Dollar sign is used to turn a relative cell address into an absolute address. The formula for the whole range is based on the formula for the top-left cell and is modified behind the scenes for each cell. Dollar sign anchors the reference to the cell in a specific column and/or row. In this case $E2 means that all cells in the second row will use the value of E2, but cells in row 3 will use the value of cell E3 because column E is locked, but row isn't and moves down. You can test this by changing the cell reference to $E$2. Now all the cells in all rows will be formatted based on the value of E2.

    There are 4 possible combinations for a cell reference: E2 (relative address), $E2 (absolute column, relative row), E$2 (relative column, absolute row), and $E$2 (absolute address).

    One example: say you have a formula in A1 that says: =D1

    If you than copy that formula down into B2 (changing both column and row for demonstration), you can get 4 different results depending on the type of cell address used:

    =D1 -> =E2 (B2 is 1 column to the right and 1 row down from A1, and so the target cell also moves the same distance from D1 to E2)
    =$D1 -> $D2
    =D$1 -> E$1
    =$D$1 -> $D$1

    Hope this helps :)

    1. Hi Zoran,

      Good point! I reworded that sentence.

  10. Hi Svetlana and or Alexander,

    I would like to add additional formatting/several rules to a current rule. At the moment I have a current formula for the "top 3 running in cells N2 to N20. It's currently work fine.

    My issue that there is other information that I would like to colour in columns L and M that would be associated with the top 3 highlighted cells in N.

    Do does one do this? Can it be done?

  11. I am using the formula below to try and format rows of data if the number in column C happens to also be in column A of Sheet 1. However, it's only highlighting the first row that meets that condition. All of the other rows that meet the condition are not changing color. Any suggestions?

    =$C2=Sheet1!$A:$A

    1. Hello!
      If I got you right, the formula below will help you with your task:

      =MATCH($C2,Sheet1!$A$1:$A$100,0)

      You can learn more about MATCH function in Excel in this article on our blog.

  12. HI there,

    I have an excel sheet with columns and want to add another which will have date of expiry in them. I would like that these dates are changed automatically when we get to a month before expiry date to amber and red once its past the date, how can I do this???

  13. I cannot get a pivot table based upon time to conditional format. I have reformatted the numbers to be "general", Time, Custom (mm:ss), text and nothing works. When I use a formula that is built-in, such as "higher than", it highlights the whole column, not distinguishing between values.

    Excel 16 Conditional Formatting of time within pivot tables is really difficult!

  14. I have excel sheet and one column I have renewal date. I want to highlight this row before one month
    So I can I use this conditional formatting
    Please revert on my email

  15. on the basis of blank cell in a column, I want the row being highlighted. plz guide

  16. Hi, if I want to leave the cells with out a color until I fill in any data, how do I proceed with that?

  17. how can i highlight entire row based on one cell,
    Ex: Column c Named "Raheem" and it become red and if i change the name , it want to change another colour

  18. Hi there,

    How do I change a colour on a row of columns when a particular column is typed into eg in that column I will type YES and the entire column line turns green?

    1. Hi, Doreen,
      let's suppose you have a table A1:D7, you type "yes" into C2 and the entire row A2:D2 turns green.
      For that you need to create a formatting rule saying:
      =$C2="yes"

      and make sure the rule is applied to
      =$A$2:$D$7

      Please read the first point of the article above in order to see how to choose a colour for the conditional formatting rules.
      Hope this helps!

  19. Hi Sevtlana,

    Could I please request your help.

    I am having a trouble in colouring a cell , which is dependent on the value of other cell in different TAB but same worksheet. for example , if source cell has value between 90 & 100 , destination cell should reflect green colour..

    Can you help.

    1. Hi, Summit,
      to solve the task you need to use "AND" function in the formatting rule. If you mean that you work within one workbook, where the source cells are in the TAB2, column A, and the destination cells are in the TAB1, column A, the formula will look like this:
      =AND('TAB2'!$A1>90,'TAB2'!$A1<100)

      If you mean, that you work with different workbooks – change 'TAB' into '[Tab.xlsx]SHEETNAME' accordingly.
      To understand how the sheet references work, feel free to check this article out.

  20. 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?

Post a comment



Thanks for your comment! Please note that all comments are pre-moderated, and off-topic ones may be deleted.
For faster help, please keep your question clear and concise. While we can't guarantee a reply to every question, we'll do our best to respond :)