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. I have a table in excel with data. I want to apply conditional formatting to it as soon as any data in the table is changed.

    Please suggest a way

  2. What if, i have several values but i use one column to sort of group, then i want all the rows with the same "anchor" value to have same color format, is that possible? Example:
    box item comments
    1 peppers 12345
    1 potatoes 132465
    3 nails 32164
    5 napkins 231354
    1 tomatoes 1321
    3 tape 1231

    and lets say i want all the rows belonging to different box # to have the same color, i guess i could do it one by one but if we are talking of dozens of boxes per say, could there be a more automated way to do this instead of doing one condition format for each?

  3. tank you very much

  4. Hi,
    If I enter completed in "I" column, the entire column should need to change? What i need to do?

  5. Just to add to the above, the formulae IF(A2"",IF(B2"",B2,NOW()),"") seem to accomplish, but my excel sheet refreshes every 1 minute, and the moment it refreshes, the time stamp changes to the local computer time (which is current and not the time when the signal came actually).
    I even tried my own like =IF(F2="Buy",IF(F2="Sell",NOW(),"")), getting the time stamp, again when the excel refreshes, the time stamp changes to the current time. For e.g. if Buy or Sell came at say 10:15 hrs, after refreshing (let us say 2 minute refresh interval), the time reflected is 10:17 hrs.
    I only hope I have clearly stated my requirement.
    Cheers
    GK

  6. Greetings,

    Quite impressed with your responses especially the frequency of your responses, never seen any one taking so much time, which is much appreciated. Namaste !

    I have a stock trading work sheet, and there are two things I am trying to accomplish and stuggling a lot :
    (1) In my trading sheet, I have Buy and Sell in a certain column which is based on certain conditions (strategy). So these Buys and Sells appear whenever the conditions are met, in Real Time (Trading sheet takes data from the internet and continues to update every 1 minute, so there are many Buys and Sells spawning from time to time). What I am looking for is the exact time stamp (data not so required as I know the sheet is being updated today). Strangely upon scouring the net, every body talks about the same formulae viz. IF(A2"",IF(B2"",B2,NOW()),"") and this does'nt serve my purpose at all. If this is all confusing, let me give a clear example here :
    Columns A-E has data like High, Low, Close, Open etc etc
    Column F has a signal : Buy or Sell
    So all I want is some column after Column F which updates the time as and when a signal appears in the Column F. The reason is I want to see which are the new signals that appeared as I am handling 200 rows of scrips.
    OR
    (2) Can Column F which contains the signal, Buy or Sell be colored in such a manner it accomplishes the following :
    (a) New signal BUY as and when it appears should carry a different color, let us say DARK GREEN
    (b) Likewise New Signal SELL as and when it appears should carry a different color, let us say DARK RED
    (c) All signals after a time decay, say 1 minute (which if configurable would be awesome), should change color. So in the case of Buy (Dark Green), color can change to Light Green and in case of Sell (Dark Red), color can change to say Orange

    Would really appreciate if you can guide/assist me in accomplishing the above.

    Warm Regards
    GK

  7. how to use formula to if possible?
    if left side of / is greater than right side change color of the text
    1200/1000 all red text
    900/1000 all black text

  8. I'm trying to do the following:

    Conditional Format (Cell Background Color in different shades from red to green) a row when it contains a date based on a specific process in the first row, i.e. first communication, presentation, first meeting, second communication, second meeting, commitment.

    The excel would look sth like:

    Row 1: first communication, presentation, first meeting, second communication, second meeting
    Row 2: 9/1, 10/1, 15/1....

    Any help as to how I could set that up would be greatly appreciated

  9. Respected Sir,
    My problem is that, i want to count Conditional Formatted (Cell Background Color) Cell count..
    so plz help me anyone to count colored cell....
    Thanks in Advance.........

  10. can i exclude cells in the row from the conditional formatting?

    so if column B has a 1 it changes row to green, but i want to exclude column K, or M, so they keep their existing color...

  11. From the below example i need to mark highlight above 10 Days rows using conditional formatting. Can anybody suggest me which formula I can use here.

    Days: 12, Hours: 13, Minutes: 51, Seconds: 43
    Days: 11, Hours: 16, Minutes: 21, Seconds: 46
    Days: 11, Hours: 16, Minutes: 21, Seconds: 46
    Days: 11, Hours: 16, Minutes: 21, Seconds: 45
    Days: 11, Hours: 16, Minutes: 21, Seconds: 46
    Days: 42, Hours: 14, Minutes: 51, Seconds: 37
    Days: 6, Hours: 17, Minutes: 21, Seconds: 46
    Days: 33, Hours: 17, Minutes: 51, Seconds: 45
    Days: 33, Hours: 17, Minutes: 51, Seconds: 45

  12. Is there a way to have the cells highlight every time the number changes? For example I have a table that has item codes and in order to make it clearer when changing to a different item code it changes color. So if I have 3 rows with the Item code 608 then 5 rows of item code 609 then 2 rows of item 610 and so on, it will highlight the 608 items and the 610 items skipping the 609 items.

    608-highlighted
    609- not
    610- highlighted
    611- not
    612- highlighted
    and so forth

    • For example, I have a column starting at A2 where I have my numbers (601,602... 900) and then all my data to the right. I want all even numbers highlighted (the whole row) and the odd numbers highlighted a different color.

      Go to the drop-down list for conditional formatting on the home tab and select "new rule".
      Select Use Formula to determine which cells to format
      Add the following formula

      =ISEVEN($A2)
      It is important not to have the second $ next to the numbers.

      Next to the Preview select "format"
      Select the Fill tab and select the color you want
      Select ok.
      Click on the drop down list from conditional formatting and select manage rules
      In the "applies to" section of the rule you just created, select the "data range" icon on the right and click and drag from the top corner to bottom opposing corner of the data you want highlighted.

      You can create a second rule with "=isodd($A2)" if you want to choose the other color.

      Hope this helps.

  13. Hi,

    I am trying to set up a formula that for when a cell changes text and matches another cell, it turns green. For example, if B2 and E2 both say 'strip', then E2 will turn green. But then if cell B2 then changes to say 'paint', and so does F2, then F2 will turn green. However, I still need to keep E2 green as it is a step by step process which tracks the progress of a part, so every step needs to be a green colour once completed.
    Cell B2 will automatically be updated from another workbook.

    If there is a way to do this without having to fill the cells in manually then please someone let me know as I have around 500 columns to fill in.

    Thanks :)

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

  15. Hi Svetlana,
    I am trying to apply conditional formatting, for example, if anyone fill red colour in cell A1 then red colour should automatically fill in cell B1.

    can you please help me on this

  16. I want to have the font colour change when I change the cell colour.

    If I make the cell red I would like the font to change to white. Is there any way to do a conditional format for this?

    • Terri:
      There is the option to modify font color in the same window where you modify fill color. After you click the Format button in the Conditional window, then Click the "Font" tab and you will see the options. The fill and font will both change colors when the conditions occur that you have indicated in the Conditional Format dialogue.

  17. Thank you so much! This was incredibly helpful and easy to follow! Bookmarking it for future reference :)

  18. How do I use this formula to highlight the entire row based on just a date entered into a cell in a particular column?

  19. is there a way i can format rows from the value that is in one cell without giving every single row a formula?

    • Levi:
      Yes, you can do this. Here's how.
      If you want to highlight rows based on the value in say the cells A2:G2 and column B will always hold the data we want to use to control the formatting of each row.
      First, highlight all the cells you want to be affected by this formatting rule. Let's say A2:G5.
      Second, click Conditional Formatting
      Third, click New Rule
      Fourth, in the New Formatting Rule window, click Use a Formula to Determine Which Cells to Format
      Fifth, in the rule box, enter a formula that refers to the active cell in the selection. Let's say we selected A2:G5, and cell B2 is the active cell. So, in the formula, we'll refer to cell B2, because it's in the active row. =$B2>70 Remember, column B holds the data we use to determine formatting for the row.
      We need to use an absolute reference to column B ($B), to ensure that the conditional formatting in all columns refers to the value in column B.
      If we use a relative reference (B), the formula will be adjusted in each column, and won't work properly. Each cell would refer to the cell to its right, instead of referring to the cell in column B.
      Sixth, click the Format button.
      Seventh, in the Format Cells dialog box, select the formatting options that you want.
      Lastly, click OK to close the Format Cells dialog box.
      That should have formatted the list of cells A2:G5.
      Test it to see if it works by entering values greater than 70 in cells A2:G2.
      You can extend the row highlighting by selecting the last formatted row and grabbing the little box at the bottom right of the cell and copying down.

  20. I have a cell that i need to change yellow if it is within 1% of another cell. I need that cell to turn green if it is at or above the percentage goal and red if it is 2% or lower than the goal. The goal is not always 100%. So if the goal was 90%, and the other cell ends up being 89% it should be yellow.

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