Comments on: How to change the row color based on a cell value in Excel

Learn how to quickly change the color of the entire row based on a single cell's value in your Excel worksheets. Tips and formula examples for number and text values. Continue reading

Comments page 16. Total comments: 546

  1. Hi Svetlana,

    I am trying to use the AND function to highlight rows. I want the row to be shaded when column K and column M contain "Yes". I highlight my whole table and apply the conditional formatting rule =AND($K5="Yes",$M5="Yes")it works but only for the top row? How do I make it so the rule is applied to the whole table?

    Also if possible, I would like to shade a different colour when the above is applied and also column I contains any value (either text or number). Is this possible?

    Thank you, I hope this make sense!

    1. Hi Shannon,

      Your formula is correct and it worked just fine on my test sheet. It might not work on your side if for some reason your conditional rule was created for the top row only. You can check it in this way:

      On the Excel Ribbon, click Conditional Formatting > Manage rules. In the Conditional Formatting Rules Manager, choose "This Worksheet" next to "Show formatting rules for". You will see your current rule and the range it applies to. If it is not correct, you can change it directly in the "Applies to" field.

      Also, please check if row 5 is really a top row with data in your table, it not, modify the formula accordingly.

      As for your second condition (when columns K and M contain "Yes" and column I contains any value), it is also possible using this formula: =AND($K5="Yes",$M5="Yes",$I5<>"") Hope this helps.

  2. Thank you, thank you! I have been trying to find a way to make this work based on the dates in the last column of several spreadsheets for a week. I guess I was just asking the wrong questions of Google, but today I found your explanation and was able to quickly (and EASILY) alter it to my needs using the TODAY()feature and adding/subtracting the # of days that would determine a different color.

    Your explanations and the screenshots were fantastic!

  3. is it possible to format a cell that contain numeric and text value on its numeric value only?
    Regards

    1. Regrettably, this cannot be done either with conditional formatting or Excel formulas because they change the format of the entire cell.

  4. hi! i am traying to format each duplicate pair in diffrent color, is this possible? infact, it is a date format and i want to have each date duplicates in same color.
    regards

    1. Hi Muzaffar,

      I don't know a way to do this with conditional formatting. Possibly, there is a way using a VBA macro.

  5. Hi,

    I have created a spreadsheet with a list of contracts including expiry dates when known - I am trying to create a conditional format for the entire row when the contract has expired - I have tried several different combinations including creating a hidden column with the TODAY() formula and using the =$L1<$M1 in the conditional formula L - being the expiry date and M - the today date, but none of the combinations I have tried are working (I have checked and all the dates are entered in the same format - but some dates that are greater than M are being highlighted also....I have also created a conditional format for when the expiry date is empty (L) to leave the format unchanged but it seems to work for some and not for others - I am completely stumped?

    1. Hi Theresa,
      Your formula is correct. I can think of only one possible reason why it may not work properly. If your table has headers, then you need to put it =$L2<$M2 to avoid the "shift" because the real data starts in row 2. Is this the case?

  6. Hi! You know the formula to highlight the row that have the same values in total score column and rank column? Thanks! :D

    1. Hi Josiah,

      You can create a rule with this formula: =$A2=$B2

      Where A and B are your total score and rank columns and 2 is the first row with data. Hope this helps : )

      1. I mean, in my case, T9 and T10 have the same rank. Is there a formula to highlight them? C:

        1. Hi Josiah,

          Sorry, I am not sure I can exactly follow you. I thought you needed to color rows if values in 2 different columns (total score and rank) were the same. But T9 and T10 are 2 different rows in the same column.

  7. I have one help
    in a cell i have keying one letter example A, and i selected same row its reflect full rows A.
    how is i do. need to help me.

  8. Thank you so much for your help. I am trying to use conditional formatting to create two separate colored sections. Here is an example of my data:

    .5 .5
    .5 .5
    1.0 0.0
    .75 .25

    The rule that I would like to set up is a green row appears when the first column is greater that 0 and the second column is equal to 0

    When both columns have numbers that are greater than 0, I would like to set up a blue column.

    Thanks!

    1. Hi Ryan,

      Supposing that your first column is A and your 2nd column is B and your table has headers, you can use these formulas:

      =AND($A2>0, $B2=0) - for green rows
      =AND($A2>0, $B2>0) - for blue rows

      As you understand, you need to replace A and B with the columns where your numbers are located. And if your table does not have headers and your data starts in row 1, change A2 to A1 and B2 to B1.

  9. Awesome, that worked. Thank you!

  10. Hi Svetlana, I am running into an issue and I hope there is an easy fix. The formula below the formatting rule works.
    Example 1:
    =AND($B2="Success", $F2="Approved") the formatting works.

    However when I add an additional formula the results don't format even when true. The issue is my spreadsheet contains the words TRUE in some cells and FALSE in others. I'm thinking the formula think these are some type of operators. When I try and use these values in the formula no formatting takes place.

    Example 2:
    =AND($B2="Success", $F2="Approved", $C2="TRUE") the formatting fails.

    I have multiple columns that have a value of either TRUE or FALSE.
    How can I get around this? I have tried applying different rules but I haven't found a solution yet.

    Thank you,
    RC

    1. Hi RC,

      You are right, Excel perceives TRUE and FALSE as Boolean values rather than text values. So, you simply need to remove quotation marks from TRUE, so that the formula reads: =AND($B2="Success", $F2="Approved", $C2=TRUE)

  11. I am trying to add a rule that will change the color of the cell (C column) if the return date (B Column) is the same (green), one day later (yellow) and over 2 days later (red). I entered the formula on the first row but cannot paste it to any other cells. I need all of column C to reflect column B as I enter the dates.

    1. Hello Sabra,

      If you have already created a conditional formatting rule for 1 row, then you can extend it to the entire table in this way. On the Excel Ribbon, click Conditional Formatting > Manage rules. The Conditional Formatting Rules Manager will open an you choose "This Worksheet" from the drop-down list next to "Show formatting rules for". You will see your current rule and edit the "Applies to" range as you need it either by typing or use the standard Excel button to select the range to the right on the "Applies to" field.

      Also, be sure to use the dollar sign ($) before the column letter in your formula, e.g.
      Green =($C1-$B1)=0
      Yellow =($C1-$B1)=1
      Red =($C1-$B1)>1

      Hope this helps.

  12. Thanks, it helped me format the document easily.

  13. Hello Svetlana

    Im wondering if you can help me i have a spreadsheet set up for work and i need to make it then when i put in a g it turns green and so on with different letters and colours. I can get it that i can change the colour however i need the number to disapper

    Hope you can help

    Thank you

    1. Hello Sarah,

      If my understanding of the task is correct, you want to change the color based on a cell's value and after that the cell's value should disappear. I don't know any way to delete cells' values using conditional formatting. And even if there's such a way, most likely this would eliminate the cell's color too (no value > no color). As an alternative, you can "hide" the value by making the cell's color and font color alike. In other words, in your conditional formatting rule you can set the font color exactly the same as the fill color.

  14. Thank you for looking into it.

  15. Hi Svetlana
    I would like cells colored based on ID numbers they contain.
    What would a formula look like that colors cells with the same values ( ID's) in a list, so the cell colors alternate, but by their ID numbers not just alternating cell by cell or by Company name as ID is linked to different locations of the same Company.
    Example:
    ID No Company
    60416 Company A
    60416 Company A
    60419 Company A
    60420 Company A
    60420 Company A
    60420 Company A
    60420 Company A
    60423 Company A
    60489 Company B
    60489 Company B
    60489 Company B
    60490 Company B
    60490 Company B
    60490 Company B
    60490 Company B
    60159 Company C
    60159 Company C
    60159 Company C
    60159 Company C
    60434 Company D
    60434 Company D
    60434 Company D
    60434 Company D
    60909 Company E
    60909 Company E
    60909 Company E
    60909 Company E
    Thanks

    1. Hi Colin,

      The only solution that I can suggest is to create a separate conditional formatting rule for each ID. In your example, there are 10 different IDs, so you'd need to create 10 different rules. VBA code might probably work too, but it should allow for all the specificities of your real data, so we cannot give any advice.

  16. i have a huge data's and each cell texted mixed color.
    i have done a formula to when ever i mark No.1 on cell will take the target cell which i want (simple : =if(=IF(A1=1,C2," ").

    The problem :
    the problem is the target cell givving me a black color text data, how i can get it as colored as original cell which it have?

    1. Hi Vic,

      If you color your original cells with conditional formatting, then you can simply extend the rules to the column to which you copy the target cells' values. If you color the target cells manually, then you can create new conditional formatting rules to change the font color based on a cell's value.

  17. Hi Svetlana,
    Is there any way to change the background colours of cells when text in those cells is changed to a date? The dates are to go on for the rest of the year(end of 2014).

    1. Hi Vanessa,

      To color cells with dates, first you need to identify the format code of your date, e.g. d-mmm-yy or dd-mmm-yy is "D1"; d-mmm or dd-mmm is "D2"; m/d/yy or m/d/yy h:mm or mm/dd/yy is "D4" etc. You can find the complete list of date codes in this article.

      And then, select a table or a range where you want to change the color of cells, and create a conditional formatting rule using a formula similar to this =cell("format",$A1)="D4" where D4 is the date format and A in the name of the column that contains dates. If your dates may be in 2 or more formats, then use the OR operator, e.g. =OR(cell("format",$A1)="D4",cell("format",$A1)="D2",cell("format",$A1)="D1")

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

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

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

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

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

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

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

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

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

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

  28. Success! Thank you very much!

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

  30. 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!

  31. 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).

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

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

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

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

  34. 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?).

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

      1. 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. =/

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

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

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

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

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

  38. Hello Svetlana,

    Thanks for your kind answer, I will try to find out more.

  39. Hello Kevin,

    If I understand your task correctly, you need to color a part of the text in a cell, i.e. "2013 year". Unfortunately this cannot be done either with conditional formatting or Excel formulas because they apply to the entire content of a cell. Probably, this can be done using VBA, but I don't know for sure. Sorry for not being able to help with this : (

    If you are looking for something different, please send us a sample workbook so that we can understand your task better and we will try to figure out a solution.

  40. Hello,

    I will try it, thank you very much,

  41. Hello Svetlana,

    I would like to know how to make one colour word in a formula which the word is refered from another sheet.

    [Example]

    The "2013 year" is at "B7" cell in "A" sheet.
    and I 'd like to use a formula on "B" sheet.
    So, hope to make this "The great idea id from 2013 year !!" words in the "B" sheet.
    But only "2013 year" is in red.
    Because, I will use the words for every year, only change "A" sheet.
    And do not miss the changed word for confirmation. So hope to make it coloured.

    The conditional formatting can not be accepted, but if it accepted a word without formula. I have tried.

    Please let me out of this question.
    Thank you!

    1. I want the cell in column L to be highlighted yellow if any cell in that row says "Holiday Inn"

      Thanks!

      1. Select column L, from L2 till the end of the data, and create a conditional formatting rule using this formula:
        =CountIf($A2:$P2, "Holiday Inn")>0

        Where P is the last column in your table.

  42. Hello Alina,

    I think you can add an additional column to your table and copy the following formula across that column:
    =IF(B2>=DATE(YEAR(NOW()),MONTH(NOW()),DAY(NOW())),IF(C2="", 1, 0), 0)
    Where B is your Delivery column and C is the Invoice column. If the date is greater than or equal to now and there is no number in the Invoice column, the formula returns 1, in all other cases it's 0. After that you create a simple conditional formatting rule for the Invoice column with a formula like this: =$D2=1 where D is the additional column. Hope this helps.

  43. Hi Parameswar,

    I am glad you've found it helpful. Thank you for your comment!

  44. Hi Svetlana,

    This is a very good post. It helped me to achive my formating I wanted.

    Thnks a lot.

  45. Hello,

    I need your help :). In my excel I have a column with "delivery date" and one with "Invoice". I would like to know the formula to colour the Invoice column when the delivery date is equal and grater than today BUT in the same time when I will enter the invoice number, the colour will dissapear (or be default).

    Thank you!

  46. Hi Rohit,

    Select your table without headers and create a new rule as described in Changing the row’s color based on a number in a single cell. In your rule, use this formula =$B2="Expired", where B is your Remarks columns. I've just tried this on my test table and it worked just fine, all rows containing the text "Expired" in the "Remark" column got colored. Hope this helps.

  47. I did not understand(although i applied rules)...
    here my problem...
    i have two coloums - 'Name' and 'Remarks'.
    i want to change the cell colour of all the cell in the column "Name" if the "Remark" column contains text "Expired" ..
    PLEASE provide me solution, better main me.

  48. I want to change the color a cell,say A1 when the count of a particular text in other cells Say A2 to A3 (which are in same row ) changes.

    Say, if the count is less than 2, the color of A1 is red, when more than 2, should be green, and greater than 5, should be blue.

    Thanks,
    Manoj

    1. Hi Manoj,

      This was a challenge!

      If I understand your task right, you need to change the background color of a cell in Column A depending on how many times a particular text is found in a specified range of cells.

      If so, you can use the following formulas to count "FindMe" text in a specified range (columns B, C, D in each row).

      =((LEN($B2&$C2&$D2)-LEN(SUBSTITUTE(LOWER($B2&$C2&$D2),LOWER("FindMe"),"")))/LEN("FindMe"))>=5

      =((LEN($B2&$C2&$D2)-LEN(SUBSTITUTE(LOWER($B2&$C2&$D2),LOWER("FindMe"),"")))/LEN("FindMe"))>=2

      =((LEN($B2&$C2&$D2)-LEN(SUBSTITUTE(LOWER($B2&$C2&$D2),LOWER("FindMe"),"")))/LEN("FindMe"))>=1

      In theory, you can use the above formulas with conditional formatting, as described in this article. However, I'd strongly advise to create an additional column and copy the formula

      =((LEN($B2&$C2&$D2)-LEN(SUBSTITUTE(LOWER($B2&$C2&$D2),LOWER("FindMe"),"")))/LEN("FindMe"))

      across that new column to count the "FindMe" instances. Then you can create conditional formatting rules based on the number in this column.

      Instead of "FindMe”, you can add a reference to the cell containing the needed text.

      Click here to download a sample workbook.

      Sheet 1 contains a complex formula to color Column A using Condtional Formatting.
      Sheet 2 is an example of Condtional Formatting using the helper column.

  49. Hi Charlie,

    Thank you very much! It's always a pleasure to get such comments :)

  50. Hi Svetlana,

    Just wanted to say thanks for this, it was really useful and helped me achieve exactly what I wanted.

    Many Thanks,

    Charlie

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