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:
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.
- Start with selecting the cells the background color of which you want to change.
- Create a new formatting rule by clicking Conditional Formatting > New Rule… on the Home tab.
- 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
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.
- 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.
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.
- The preview of your formatting rule will look similar to this:
- 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.
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.
- On the Home tab, in the Styles group, click Conditional Formatting > Manage Rules… .
- 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".
- 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:
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.
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:
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).
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")
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)
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
I am trying to fill an entire row a different colour depending on date(month).
I have set up conditional formatting to give different colours in the cell containing the date using cell value, but I cannot make this stretch across the row, every formula I have tried does not work.
How can I get around this?
I have entered a date and time in a cell and I want the cell next to it to turn green in exactly 24 hrs. How do I do this?
Hi Reuben,
Assuming you have a date and time in cell A1, you can create a rule based on the following formula:
=(NOW()-$A1)*24>=24
I want to highlight a CELL based on number of times its values changed.
e.g.
1)IF the cell value is changed '2nd TIME' it should highlight "Green".
2)IF the cell value changes '3rd TIME', it should highlight "BLUE" and so on...
Hi admin
how to highlighted condtional formatting color row A number above row B also colour not updated 0.
Regards
SP
I would like to be able to change a row to a colour if the cell G2 contains "A" to yellow "B" to green and "C" to red. I would like to continue this in all rows of column G. My issue is I can do this for row 2 but when I try to do it for the column G when I put text in 'G2' it changes all other rows.
Will I have to create a macro?
Hi Karl,
A macro is not needed in this case, the task can be handled by a conditional formatting rule. The key point is to use proper cell references - absolute column and relative row: =$G2="A"
Also, make sure you apply the rule to a range beginning with the same row as referenced in the formula, row 2 in your case.
Hi admin
how to highlighted condtional formatting color col A number above col B also colour not updated 0.
Regards
SP
Hi Admin
What i want is really very simple but im having trouble.
i have 6 colums 2A to 2F i want all the background colours red there will be a number in colum 2A and 3A and when i put a number in colum 4A i want all colums 2A to 2F to change to gree ?
Regards
justin
Hi,
I am having trouble changing cell colours for some reason. I have used the formulas as suggested but the formula will not work. I'm not sure what I am doing wrong! I want to change the colour of the cells in the L column if they are blank and if the cells in the W column have been entered as 'No'. I have entered the formula as =AND(L2="",W2="No"). Could you tell me what I am doing wrong as I cannot work it out?
Many thanks
Hi Farhat,
The formula is correct. Just make sure the rule applies to column L beginning with cell L2. Also, you'd better fix the columns by using the $ sign:
=AND($L2="",$W2="No")
Hey Admin. Hoping you could help me out here.
In my excel sheet i have columns for start date, number of months and end date. If the number of months is 7, 2 columns, i.e column D and E must get highlighted. If number of months is 3, columns D,E and F must be highlighted. How can i do this. Please help.
I have a data with Columns; Entry No, Date, Activity, Target Date, and Completion Status.
I want My rows color to change based on Target Date and Completion Status.
if Target date is within 7 days row colour must be Orange.
if Target date is due row colour must be red.
If Completion status is completed row colour must be Green
pls hlp me
Thanks for answering all of our questions!
I have a problem with using this formula.
I have 9 columns A to J
i'd like to have a row changed to a specific colour depending on the contents of the cell in column C
C has two states, 'INSTALLED' and 'REMOVED'
essentially if the cell reads 'REMOVED' then i want that row to be colored yellow. If it reads 'INSTALLED' i want it colored green.
It seemed like you already covered this in the article but your process did not work for me. I even tried adding new test rows and changing the value of the cell in column C but there was no change.
The formulae i used were "=$C="REMOVED" and "=$C=INSTALLED"
Thanks for your help!
Hi Bob,
You need to refer to your top-most cell in the formula. For example, if your data begins in row 2, the formulas are as follows:
=$C2="REMOVED"
=$C2="INSTALLED"
after trying it again, i realised that i had selected the cells using the column headers rather than selecting the cells by draggin a selection or shift-clicking.
All seems to work now!
Thanks!!!
Thanks for your help Svetlana, that is almost perfest but I want the formula to work whatever date I put in column M, is it possible? :-)
Julie,
Of course, it's possible. In this case, the formula is even simpler :)
To color a row if a cell in column M is not empty (contains any value - number, date or text):
=$M2<>""
To color a row if a cell in column M is a number or date (dates are stored as serial numbers in Excel), but do not color a row if column M contains a text value:
=ISNUMBER($M2)
your blog has helped me so much but I just need a bit more help, I am using the following formula to shade a whole row green once the word 'completed' has been added to cell M but I would really like this to be a 'date' rather than the word 'completed', I have tried a few things but I am a beginner on excel. The formula I am using is =$M2="COMPLETED" is there an easy way to change this to a date? thanks in advance
Hi Julie,
If you want to highlight a row when a certain date is entered in column M, you can use a formula similar to this:
=$M2=DATEVALUE("01/01/2015")
You can find more formula examples of Excel conditional formatting for dates in the following tutorial:
https://www.ablebits.com/office-addins-blog/excel-conditional-formatting-dates/
If you don't find an answer there, please elaborate a bit on your task and we will try to make a proper formula.
I column that contain numbers ranging from -001 to -374.
I want to have a cell that if I type in a matching number to any of the -001 to -374, then the row containing the matched number will be highlighted.
Please can you help.
Hello Svetlana,
I want to get the next cell in my row to have a specific color highlight depending on my current cell having a date or number or text. I want a different color for each type of entry. I am a novice and have researched much. I have found the best info here but i still cant figure it out.
Any guidance would be appreciated.
Thank you,
I would like the entire row to be highlighted based on the contents of column I ---- either that there is NO value (rather than ANYTHING) if that's possible.... or if there is a "," in the cell text.
Thank you so much for any help that you can provide.
Let me try that again.
I've tried a few of the combinations posted, but it only ever changes the background for the I column, not the entire row. Also, I would like this specific formatting to begin with Cell I2, rather than I1.
Thanks again.
Hi Hollywil,
Before creating a rule, you need to select the entire rows you want to highlight for a rule to get applied to several columns rather than a single column.
Also, when creating a rule, make sure that you select a range of cells beginning with row 2. You can use the following formulas in your rules:
Highlight rows with "NO" value in column I:
=$I2="NO"
If there is a comma in column I:
=SEARCH(",", $I2)
How about highlighting a block of cells based on the value changes in just a single column.
For instance, say I have columns A and B. Down column A I have numbers like 1,1,1,2,2,3,3,3,3,4,4,4,5,5,5, and whats down column B is non-consequential for this example. Every time column A changes value (from 1 to 2, 2 to 3, and so on), I want to highlight the cells in both column A and B with a different color. The color can simply rotate between two colors.
Say it was setup like this (x is just some other information)
A B
1 x
1 x
2 x
2 x
2 x
3 x
3 x
I want A1,A2,B1,B2 to be one color, then A3,A4,A5,B3,B4,B5 to be another, and so on.
Thanks for the help in advance.
Hi Kyle,
If my understanding is correct you are looking to alternate row colors based on a value change in column A. If so, you can find the right formula and detailed instructions in the following example:
https://www.ablebits.com/office-addins-blog/alternate-row-colors-excel/#value-based
Thank you Svetlana, this article was very helpful.
I have a task I perform on a date and I enter the date into Cell A1. What I want to do is have the cell B1 turn to red when I am 7 days past the date I entered into Cell A1. Can you tell me how to do this?
Hi Bruce,
Try creating a rule with this formula: =TODAY()-$A1>7
I need to change the colour of the font in the row that the date is three years from today (All expired items). When I use conditional formatting the column the date only changes please help. Regds, Omar