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,
    Was wondering if anyone could help.
    I'm trying to find a formula that will highlight a cell if that cell = 227 and the cell below = 867 or 965.
    Thanks in advance,
    Carl

  2. This is amazing. Thank you!

  3. Hello,
    I would like to have individual cells in one column highlighted if they are equal to or greater than a percentage of the value of the cell in the previous column.
    Is this possible to do?
    Thanks in advance,
    Paul.

  4. I have 2 conditions in one column yes or no
    Yes have pink color and no have yellow so which is the formula is used here to do so i wanna to do samething in other sheet
    Automatically it converts when I write yes or no

  5. Hi,
    I want my spreadsheet to change the color of each row only when an item number I have in Row B changes to a new Item number. These item numbers are not equally spaced and have no consistent scale or system to them.

    The only identifying factor is that the number changes to a different number, sometimes 5 rows apart other time 30 rows apart. The spreadsheet is over 70,000 rows. Solutions?

  6. Hi everybody,
    I need help please, i want to apply rules in my excel sheet,when i type specific word (Friday) row and column colour should be change, please help me resolve this.

  7. I want to color rows whennI type in yes or no of a certin Item in our inventory has been cycle cou ted... please help

  8. please try to help me i have workbook in that workbook i have two sheet (Data Entry Form) & Monthly report per day in calms and in rows name time i want to change cell background color in monthly report. Just i put in data entry form name of site and in monthly sheet automatically change cell color by site.

    • i am working excel workbook.

    • Hello,
      For me to understand the problem better, please send me a small sample workbook with your source data and the result you expect to get to support@ablebits.com. Please don't worry if you have confidential information there, we never disclose the data we get from our customers and delete it as soon as the problem is resolved.
      Please also don't forget to include the link to this comment into your email.
      I'll look into your task and try to help.

  9. How to "Conditional format all cells by using a four-color scale".

    • Hello, Kobus,

      I'm afraid it's impossible to use four-color scale in conditional formatting. But perhaps VBA macros can help you. You may try to find the solution in VBA sections on mrexcel.com or excelforum.com.

      Sorry we can't assist you better.

  10. Hi, I want to ask you question and need your help

    want formula to do the following: if cell G1=text and date in the selected cell J1 is before 60 days then high light the row or selected cell

    and if cell G1=text2 and date in the selected cell J1 is before 90 days then high light the row or selected cell

    and if Cell G1=anyothertext please do nothing

  11. What formula can I use to change the font color of a row to red if a cell in that row is a date prior to today? And how would I repeat that for all subsequent rows?

    Thanks!

  12. Hi,
    Why i follow you but it highlighted all of selection area, not only rows which contain the cell has specific words i defined?

  13. hi,
    in may excel sheet lots of column and row, in last column header is status that contain DIS, RFD, RFI, 2, 3, 4, NP etc. If i put up DIS IN THAT COLUMN TOTAL COLOUR OF RO changes to green. how i do these

  14. This post was very helpful, but still need some additional assistance:

    I have a sheet used for inventory for deployed computer hardware. Not only is this data stored in the sheet but parts of it are also stored in our ERP system. And accounting needs to know when a computer is deployed so they can move the cost from IT to the deployed department. So I created columns for ERP and Accounting Notified that when those tasks are completed I simply put a Y in the cell. If there is a Y in either cell, highlight the row orange, and if there is a Y in both cells highlight the row green. This works fine when working with 1 row, but I need to replicate this down the entire sheet. What is the best way to accomplish this?

    • Got it figured out. Had my conditional formula looking at a specific cell instead of a column.

      • Hi Brian, I am having a similar problem to the one you described here in that I would have to replicate the formula for each row individually for it to be highlighted if a cell in the row contained "Completed". Can I ask you how you rectified your problem? Thanks

  15. thanks for this lesson ... really appreciated

  16. Sorry, should be this..

    What I’m trying to do is basically have 4 rules determine what colour to highlight an entire row based on what percentage it is in a cell. Not sure if they can be combined or not.

    If Column B percentage is 0 then highlight blue
    If Column B percentage is >15 then highlight yellow
    If Column B percentage is >50 then leave white

  17. Hello first of all, very grateful for the article and your help.

    What I’m trying to do is basically have 4 rules determine what colour to highlight an entire row based on what percentage it is in a cell. Not sure if they can be combined or not.

    If Column B percentage is 0 then highlight blue
    If Column B percentage is >15 then highlight yellow
    If Column B percentage is >50 then leave white

  18. Your first example doesn't work. In fact, the picture that shows the result doesn't even show what you say it does.

    • Hi Stephen,

      The example works, but a wrong picture somehow showed up on the blog. Thank you for pointing that out, fixed!

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

    • 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!

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

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

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