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 Paul,

    I am not 100% sure that I understand your task correctly, so let me check. If you have 6 in A1, then you want the next 6 cells (B1 – G1) to contain "x". If you have 5 in A2, the next 5 cells B2 – F2 should contain "x" and so on. The maximum value in A is 24. If so, then you can copy the following formula to B1:Y1 and across the same range in other rows: =IF(COLUMN(B1)-1 <=$A1, "x", "") No conditional formatting is needed.

    P.S. I think I have to let you know that I gave up on this task after several unsuccessful attempts.
    The formula was written by Dmitry, one of the best Excel developers in our team, just in a few seconds : )

  2. Hi Svetlana,

    Can you advise how to make cells adjacent to 1 cell with a numeric value change colour or ideally return an x symbol, ie
    Assume cell A1 contains value 6, I need the number of cells adjacent to ideally contain the x value (or be coloured) based on the number in A1, so B1 - G1 would contain x. Need this formulae to work up to a value in A1 of say 24 max. Is this possible ?? - many thanks.

  3. Hi Helen,

    You need to enter the absolute address of the column =ISERROR($A1). If errors may occur in other columns as well, then you need to create similar rules for columns B, C, etc. Alternatively, you can try to combine them all in one rule using the OR operator, e.g. =OR(ISERROR($A1),ISERROR($B1),ISERROR($C1))

  4. Hi Svetlana

    I am trying to make an entire row red when there is one or more #N/A errors. I have used =ISERROR(A1)and selected the range as =$A$1:$AI$16 but it only makes the cells with #N/A in them red not the whole row.

    Please can you help?

    Thanks
    Helen

  5. Hi Son Pratap,

    In your case, you need to select the whole table and create a conditional formatting rule of the type "Format only cells that contain". Then under "Format only cells with", choose the following options: Cell value, equal to, A. You can find the detailed information on how to do this in my other article: How to change background color in Excel based on cell value. Hope this helps.

  6. Hi Svetlana,

    I want to make a sheet which contains only words A,U,P,EL. The condition is when I type A in any cell of the table the background of that perticular cell should change automatically to yellow. and when I type P in any cell then background should change to green like by typing other words they should also change the colour of backgound of any cell in same table.

    Thanks
    Son Pratap

  7. Hi Alan,

    The only solution that I can come up with is using the =AND formula like this =AND($A2"", $B2"", $C2"", $D2"", $E2"")
    It works fine if a table has only a few columns, but this may not be the best approach if you have a large table because as you understand, you would need to list all the columns in the formula. Regrettably, I cannot suggest any better alternative.

  8. Hi Svetlana,

    Was wondering if you could help me please. I have a table made up and i am wanting to highlight an entire row, only when all the cells in that row have information of any kind(text or numbers)in them. So the row would stay unhighlighted if any of the cells were left blank. Basically the entire row would highlight automatically when all cells are complete.

    Many thanks

    Allan

  9. Hi Tatumrs,

    I tested that formula on a table that pulls data from another sheet using a CONCATENATE formula similar to yours, and it worked properly. In fact, it does not really matter whether you enter a value directly in a cell or pull it from another location. This formula (=$E4="x") is very simple and should work anyway, unless you have some specific data format, e.g. dates. Anyway, it's hard to say why it does not work for you without seeing your real data.

  10. Line 26, 27, and 28.

    I attmepted to place the formula you suggested in the conditional formating and it is not working. Any other ideas?

    Ex. I am wanting cell B4 to highlight if cell E4 has "x".

    However, The data is cell E4 is pulled from a different location based on the formula =CONCATENATE(U7G!E8," ")

    Thanks for your help.

  11. Success! Thank you very much!

  12. Hi Chris,

    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. Hope this is what you are looking for.

  13. Hi Svetlana,

    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!

  14. Hi Tatumrs,

    I think you can select the entire column B and create the conditional formatting rule based on this formula =$E1="x" (or =$E2="x" if your table has headers).

    • Hi Svetlana,

      How to colour a row where text mentioned in Column A2 to E2= "Yes".
      But if any of the cell is "No" then that row should not get highlighted.

      A B C D E
      Yes Yes Yes Yes Yes
      Yes Yes No No Yes

      Regards,
      Rajnish

      • Hi Rajnish,

        You can select all the rows you want to highlight and create a rule with the following formula:

        =COUNTIF($A2:$E2, "yes")=5

  15. column e text is also pulled from the other tabs based on the same formula

  16. I am working a spreadsheet that contains several tabs or worksheets. The summary page is pulling information from the other tabs based on the formula =CONCATENATE(U7B!E91," ")

    Now, on my summary page, I am wanting to change the color of a cell in column b if a text in column e is "x". Column b is a name gathered off the above listed formula and column e represents if they are a pool player

    Thanks for the help

  17. Hi Byte,

    As far as understand you output the days of the week in some custom format similar to "ddd" format that displays Mon, Tue etc. If so, then you can create a conditional rule based on this formula:
    =OR((text(A1,"ddd")="Sat"),(text(A1,"ddd")="Sun"))=TRUE
    where A in the name of the column where your =DATUM formula is used.

    You will only need to change "Sat" and "Sun" exactly to the text that your formula returns, replace "ddd" with your cell format, and use the analogs of "OR" and other operators in your language (German, right?).

    • Hi Svetlana,

      I've tried your formula but unfortunately it doesn't function. I've tried to change some settings of the formula (like MS Office 2010 doesn't like = before OR command or other commands.) I've tried some other things, but no result. I have changed the name of the days as you had mentioned, from Sat to za en from Sun to zo. These are the short names of the week days in Dutch. Do you have another solution for this. If you want, then I can send you the Excel file.

      Kind regards and thanks in advance,
      Byte

      • Hi Byte,

        Yes, please send your workbook to us at support@ablebits.com and we will try to figure this our (please add Att: Svetlana to the subject).

        BTW, =OR worked well in my Excel 2010, English localization.

    • Hi Svetlana,

      This is almost exactly the same problem I'm having. And the formula you post works but only partially. When I type the formula you list above, It only colors 2 of my cells. No cells are hidden and when I tried it in a brand new sheet using the same formulas only one cell on that sheet changes color. What am I doing wrong? I am only using the first part of the formula you posted because I only need to color cells in the row containing Sunday. This is what I put in the formula box in Conditional Formatting: =OR((text(A6,"dddd")="Sunday"))=TRUE

      Thank you for your help!
      Tara

      • Oh and I'm using =WEEKDAY(A1) in my A6 not =DATUM. It took me a long time to figure out the Weekday formula, I'll be really bummed if I have to change it. =/

  18. Hi Svetlana,

    I have a little problem with an Excel sheet which is made by someone else who left the company. According to a formula =DATUM(D$3;SOM(C$43:O$43);B7)is the day of the month set in the cell like mo tu we th fr sa su. Wheneve I change the year the days of the month changed automatically. What I want to do is color the row of sa and su but all what you memntioned above couldn't help me. How can I realise this?

    If it is not possible, is there then another way to set the days of the month sothat I can change the color of the row of weekend by a formula or else?

    Kind regards,
    Byte

  19. Hi Sumesh,

    If my understanding is correct, you need to change the font of 3 and 4 in your example. If so, select the entire first column (say, column A) and create the conditional formatting rule based on this formula =ISERROR(MATCH(A1,$B$1:$B$10000,0))=FALSE

    After that select the second column e.g. column B (it's very important to select the entire column, so that your rule will apply to =$B:$B) and enter this formula =ISERROR(MATCH(B1,$A$1:$A$10000,0))=FALSE

    Choose the needed font color for both rules and enjoy the result : )

  20. Hi

    I would like to know how to change the color of font if in 2 colum numbers are same but not in sequence ?

    If in colum A there is number like., 1,2,3,4,5 & If I type 3 & 4 in next colum like below. So can I change font color of same numbers? and How using formula?

    E.g.

    A B
    1 4
    2 3
    3
    4
    5

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