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,

    Thanks for such a useful page.

    I want to extract only year from the date column feed with different formats, but unable to do so.

    Please help me with this.

    Best Regards,
    Zohaib

  2. Hi
    I wondered if you might be able to help.
    I have a spreadsheet on which I detail all my spending each month with a column for each shop/supermarket.
    In A1 I have today's date with the formula / =TODAY() /
    In Column A I have the date and have done conditional formatting so that this cell is highlighted if it is the same date as A1.
    What I really want to do is highlight (change the colour of) the whole row when the date in column A = today's date.
    Thank you
    Regards
    Chris

  3. Hi Svetlana
    Thank you very much for doing this, very clear and easy to follow, much appreciated.

    Thanks

    Dave

  4. Hi Svetlana,

    Can you help please?

    I have seen above the following

    "I have one column (J) which is "date of sale". This only has a value if a sale has been made. So, I want to highlight all the rows which have a date in column J (essentially highlighting all the rows where I have made a sale, and leaving the ones where the sale has not been closed blank) with your response of Try selecting the whole table and then create the formatting rule with this formula =$J2"" (assuming that your table has headers). It will color all the rows that have any value in column J."

    I have a similar issue but its for 2 columns (E and H) but a date will only be in on or the other - never both. hope this makes sense.

    would really appreciated your help please :-)

    i am trying to make this work with dates in either column e or f

    Sorry to trouble you, but I cannot make this work for a date!
    I have one column (J) which is "date of sale". This only has a value if a sale has been made. So, I want to highlight all the rows which have a date in column J (essentially highlighting all the rows where I have made a sale, and leaving the ones where the sale has not been closed blank)
    Can you help?
    Thanks!

  5. Thank you
    I found the solution.
    =ISNUMBER(Search("p1",S3))
    This could be applied to all payments.

  6. Payment 1 Payment 2 Payment 3 Payment 4 Paid 1, 2, 3, 4

  7. Hi!
    Thank you for this site that produces excellent information.
    I would request your help!
    I have a table and one cell will contain (Paid 1, Paid 2, Paid 3).Each will be written after one month. These refer to other cells of payments. (payment 1) (Payment 2) and Payment 3). So I need each cell of payment to be highlighted if I write (Paid 1, Paid 2, Paid 3) in the last cell.
    Appreciate your help
    Imad

  8. if a column contains "any date" i want to fill a color to the entire row in excel

    • Hello Naseef,

      Select the rows that you wan to highlight, and create a conditional formatting rule with the below formula, where A2 is the top-most cell with a date:
      =ISNUMBER($A2)

  9. very helpful thank you!

  10. I am sorry. My question was a bit confusion. Here is the revised one: Are we only able to check one column at once? Is it possible to check entire worksheet for a keyword(s) and then highlight all the rows have hit in different columns?

    • Hi Mike,

      I don't know a way to check the entire worksheet. However, if there are a limited number of columns to check, you can use the following formula to highlight rows that contain a specific text in any of the concatenated columns:
      =SEARCH("text",$A1&$B1&$C1&$D1)>0

      Where 1 is the top row that you want to highlight.

  11. Are we able to check one column as once? Is it possible to check entire worksheet for a keyword(s) and then highlight all the rows have hit in different columns?

  12. Hi,
    I have a table where the text in column N is either "Live" or "Off-hired" and I would like the whole row to be highlighted whenever "live" occurs. I have tried a number of the formulas above but I can't seem to get it to work.
    please can you help?
    Thank you very much :)

  13. Is it possible to insert icon sets from different sheet in the same workbook

  14. Hi,

    I need to change the cell color based on the previous cell value.

    For example
    A B
    1
    2

    If B2 value is greater than A2, then B2 value automatically change into green color. If it is less than A2, then I need to change into red color like wise it will need to happen when C2>B2, D2>C2 etc…

    Is there any way to do this?

    Thank you for your help.

  15. Thank you very much. This is exactly what I was digging in Microsoft help center for 30 min.

  16. hi there,

    its very nice and helpfull,

    Thanks,

  17. Hi there,

    so on my Excel, I have color shaded for the status, green for good, red for bad, etc.

    Now I need to change those colors to a status value in text i.e. good, bad, opportunity for a migration to a CRM?

    is there an easy way to do this for several hunrded entries on Excel?

    thanks

  18. Can you please help me, I'm working on a spreadsheet and I want my J4:AI4 to change it font color to red with the following condition: if column G = 10, column I < 17 and column G = 20, column I <7 and the even rows from J6 to J1154 < 0.

  19. I have a spreadsheet that is currently in red font. In column F an x is placed if that row has been edited. Is there a formula that can be used so that when the x is placed in column F the entire row changes to a black color font?

  20. I have four columns. The first one has a name and the next three have numbers. If the first three columns are all 0 I want the name to turn red. Only if they are all 0 though. If just 1 is above 0 it needs to turn yellow. If they are all above 0 then it needs to turn green. Is there any way I can do this?

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