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. thank you so much Svetlana Cheusheva

  2. Hi Svetlana,

    I am trying to automatic highlight the high value in each row.

    For Example threre are some figure in each coloum i.e. :-

    ColumnA ColumnB ColumnC ColumnD
    1. p 10 15 12
    2. n 15 12 14
    3. q 10 04 20
    4. r 15 20 25

    now, which condition i used that the autmatic highlight the high vlue in each row.

    Regards,
    Prashant Johari

  3. Hi Svetlana

    I am trying to figure how to format my worksheet so that it identifys by changing colour if a number is less than the number it was previously e.g. something weighing 12kg then in the next coloum, ideally they will be 13. But if it ends up weighing less, e.g. 11, then it would highlight this for the entire worksheet not just for the one row/cell.
    Are you able to help me? I am tearing my hair out!
    Thanks
    Sophie

  4. I need a formula that will make cell "A3" turn Green when cells "E3 through L3" contain the letter "Y"

    and also

    "A3" turn Red when cells "E3 through L3" contain the letter "N"

    • Hi Chris,

      You just need to put all these conditions in the AND formula, like this:

      =AND($E3="Y", $F3="Y", G3="Y", etc.)

  5. Hi Svetlana Cheusheva,
    I wanted to send reminders to the stakeholders while exceeding 3 days from last reminder date. I have used the below formatting but I could not highlight the entire rows and also want to ignore weekends (Saturday and Sunday).
    Formula used, E.g.,
    =$D$2-TODAY()>=3
    Thank you.

    • Hi Bharath,

      First off, please check whether your rule applies to the entire rows you want to highlight (without the column headers).

      Assuming that the last reminder date is in column D, you need to change your formula as follows:

      =TODAY()-$D2>=3

      Please pay attention that $D2 should be a mixed cell reference (absolute column - with $ and relative row - without $).

      Finally, create one more rule to exclude Saturday and Sunday (do not choose any fill color), move it to the top of the rules list and check "Stop if true" next to it:

      =WEEKDAY(D$2,2)>5

  6. Sir,
    My problem is when I put formula in one the background and font color should change accordingly.
    For example:
    A B C D E F G H I
    1 BUY SELL PROFIT
    RATE RATE /LOSS
    2
    3 2500 3000 500 I WANT THIS CELL BACKGROUND GREEN
    4
    5 6000 5500 -500 I WANT THIS CELL BACKGROUND RED

  7. hi just asking please help how to change the color automatically if i input # 4 it will change in other sheet in the entire row it will change color blue.

    for ex. 1 pink
    2 yellow
    3 green
    4 blue

  8. How to change a row color based on a number in a single cell worked great. Except I also have your formula to count cells by color and the colors for the conditional formatted cells shows as "no color" in the cells formatting.

  9. Hi,

    There is any data in xls but somewhere we are correcting the numbers so i want to highlight such raws where we are doing the correction.

    Can you please help me with this?

    Thanks
    Hardik

  10. Hi Experts,

    I have copy pasted data from some website and pasted the content in a cell , say "HELLOWORLD". HELLO is in blue and WORlD is in black.I need to put a ',' after the blue font. so it looks "HELLO,WORLD"
    Can i do it? if yes how ?

    Note- for limited number of records i could have done it manually but i have lakhs of records and i cannot do it all alone manually.
    I want to automate it with some code.

    Please help

    Thanks in advance
    SSK

  11. Hi,
    Can you please help me with my formula?!

    =OR($D>=20%, $E=8%, $E>=4,$E=3%, $E>=7)
    COLOR GREEN

    =OR($D<=20%, $E<=3),OR($D=4,$E<=6),OR($D=7)
    COLOR RED

    1-3 ranking + ctr >20% = green
    1-3 ranking + ctr 8% = green
    4-6 ranking + ctr 3% = green
    7-10 ranking + ctr <3% = red

    Thanks
    Chantel

  12. Hi there, thank you for your helpful article! I am making a two sheet workbook intended to show my company what customers we can contact to let them know a product that they are looking for is coming in on our next shipment. The first sheet is the customer's information and in column A is the style number of the product they are looking for. The second sheet will be where we copy and paste the style numbers of everything we are expecting in on our next shipment. I need to make each row in sheet 1 highlight if the value in column A matches any value in column A of the second sheet. Note, I will be deleting and reentering all style numbers in column A of the second sheet to always be showing our most current shipment, so I cannot enter a specific value to match in the formula because it will always be changing. Thank you for your help on this!

    • Please post a small sample workbook with your data on our forums and include the result you expect to get. We will try to help.

  13. Awesome, thank you SO much!!

  14. Hi Svetlana

    B10060000005
    B10060000005
    B10060000006
    B10060000006
    B10060000007
    B10060000007
    B10060000008
    B10060000008
    B10060000009
    B10060000009
    B10060000023
    B10060000023

    could you please assist I need to give each row contain the same cell value same color, example entire row contain B10060000005 with green, B10060000008 blue ...etc, thank you

  15. In my excel I have two columns Colum B "Account Type" and Column C "Account name"
    Column C has all the account names such as Global travel etc... and Column B which is account type as either Account or Agency mentioned in the cells

    What I am looking for is to have a formula which highlights cells in column B and C when it finds the word "Travel", "Tour", "Agency" in column C and word "Account" in column B .

    Please note it should only highlight when both these criteria are met

  16. Any one Help me

    Q. 2 If we put the value >0 to <2000 in column B then column C should be red. In conditional formating

    Value Cell Color
    2
    4
    -10
    800
    -1691
    1500
    3500

    Need Solve

  17. Q. 2 If we put the value >0 to <2000 in column B then column C should be red. In conditional formating

    Value Cell Color
    2
    4
    -10
    800
    -1691
    1500
    3500

    Need Solve

  18. If I have a worksheet with data across columns A to G, I want to use the formula =MOD(ROW(),2)=0
    to alternate row colours BUT I need to be able to insert rows sometimes when the data in Column D needs to be the same colour as row above .....

    Thanks in advance

  19. Hi Svetlana,

    Could you please help me.

    I want to change the value of cell based on this condtion.

    if A1 cell is coloured Green and B1 cell has value "Yes"
    than B2 automatically gets converted into "Yes".

    Thanks in Advance

  20. Hi Svetlana,

    Could you please help me.
    For example, if A1 have a text then B1 will be filled by color,
    if A2 have a text then B2 will be filled by color.

    I trying to do the formula, but the result is Even A2 blank, B2 filled by color.
    Any idea for the formula.

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