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
Hi I am trying to improve a document in which I am already using conditional formatting. At present, Cell H9 contains a drop down list of equipments, when nothing is selected in H9 the background is blue, however whenever an equipment is selected the cell is set for no highlighted colour. In Cell H49 I have to record the current software version of the equipment, again if the cell is empty the background is blue, if the software version is correct the background is clear, however if the software version has been superseded this cell reverts to red.
The specific data within H49 is directly related to the data entered in H9, but as yet their conditional formatting is not set up as such, therefore any current version of software is always indicated as being correct, even if the equipment in H9 is not the correct system for the selected software version.
If as an example the systems are called a, b and c and their software versions are 1a, 3b and 4e, respectively, is it possible to produce a formula that ensures the conditional format of H49 is directly related to the specific data in H9 such that:
1. With no entry in H49 the background is Blue (This code is curently in use).
2. Only when H9=a and H49=1a, or H9=b and H49=3b or H9=c and H49=4e, the background is clear(denoting software is up to date).
3. Any other configuration is highlighted red(Incorrect software version for system selected in H9).
If you can assist it would be greatly appreciated. I look forward to recieving a response.
Regards
Paul
Hello Paul,
If my understanding of your task is correct, the following formulas should work a treat.
So, select the cell you want to highlight (H9 or H49) and create 3 rules:
Blue: =$H$9=""
No color: =OR(AND($H$9="a",$H$49="a1"), AND($H$9="c",$H$49="e4"), AND($H$9="b",$H$49="3b"))
Red: =OR(AND($H$9="a",$H$49="a1"), AND($H$9="c",$H$49="e4"), AND($H$9="b",$H$49="3b"))=FALSE
This tutorial or instructions looks great, but doesn't work easier at least for me. I am using Excel 2010, whenever I use the formula |=SEARCH("Due in", $E2)>0| I am getting an error :(
--
Jena
Hi Jena,
What exactly error do you get? This is a very simple formula, and there is absolutely no reason for it to produce an error.
I can think of just 2 possible reasons:
1. Straight quotes in the formula were replaced with smart quotes while copying. Please try retyping the formula directly in Excel.
2. You have a different List separators set in your Windows Regional settings, e.g. semicolon, which is the standard for European countries. You can check it in Control Panel > Region and Language > Additional Settings. If this is the case, the correct formula will be =SEARCH(“Due in”; $E2)>0
If neither is the case, you can send me your sample workbook at support@ablebits.com and we'll try to sort it out.
Hi Svetlana
I am using excel 2007 I am an absolute begginer to excel and I am trying to create a work sheet to map the progress of a given number of tasks to be done to complete one job before moving on and repeating the same tasks to the next job and so on.
C2:K2 are tasks to be done, each I have given their own color.
Apon entering say 091014216(09/10/2014 2.16pm)in the cell under first task I want the intire row to change to that color at the same time adding 10% to K2(% complete)and when I enter say 091014529 in the cell in the next column the color of the row would change from the previous colour to this tasks color (and add 10/20% to K2. And so as the rows get filled with numerous jobs I can at a glance see the the color a particular job is at and and how near completion. I tried the above formula in the new formatting rule window but it only changed the color of the one cell I entered C4 even though I entered =$C4>0. Is this because I`m using 2007 excel? or can this be done?
Hello Joseph,
For me to be able to help you better, please send a workbook with your sample data to support@ablebits.com and specify how you want to highlight the cells.
Hi Shetland
Thanks for your prompt response unlike my own.
Very sorry for not getting back sooner but I am away from my home computer where I have this workbook started. As soon as I am back I will be in touch.
Joe
Svetlana - you're awesome! Thanks so much for the great tutorial. Very helpful in my keyword research efforts - and I will link to this page when I blog about it :-)
nazdrovya
Gary
Thank you very much for your kind words, Gary! Nice to know my article has been helpful.
What if I want to color an entire row with a cell that containing a specific text
Hi Lulu,
This is exactly what this tutorial is about - how to highlight the entire row based on a value in one cell. The following section provides a few example of formulas for text values:
Change a row's color based on a text value in a cell
Hi,
I understand conditional formatting well.
I have set of combinations, each of which corresponds to a row (Say 10 Set with 5 values for each set. So 10 X 5 Table). So If I select any cell in a row, I should project corresponding colour code based on values (5) on this row.
I can do conditional formatting for colour coding. But how can I take a set of input at a time to do so.
Can I do this in Excel?
Hello Shun,
If my understanding is correct, you want to pick the color code of the current cell and use it as the background color for all the cells in this row.
Unfortunately, I don't know the way to fulfill this task using conditional formatting formulas. Most likely, a special VBA macro is needed.
Hi Mam,
i ve to change colour based on a cell value and i couldnt find any answers. for eg., if cell a1 value is 2,the next two coloums must be coloured if it is 3 then next three colums must be coloured. when i increment the cell value the no of colored coloumns must be increased. plz help me...
Hi,
I wanted to learn using formula on color changing in a cell as reminder. For instance, if say a lease for Mr. XYZ expires on 15/12/2014 and i want a reminder 2 months in advance to follow up renewal/non-renewal. How do I do that if I wish the color to change and understand that it is time for a follow up?
Hi, I want each cell in column "D" to be colored Yellow if the value is less than that of the matching cell in that row in column "C". I can do it one at a time but I have hundreds to do. Is it possible to write one conditional format for all?
Hi,
I have problem in solving for the formula. I'd like the three cells have same color with I select name for example "Jimmy".
Date Doc Id Auditor
Please advise for the appropriate formula using the conditional formatting.
Thanks
I work with students and I need to know if they are behind. If I have a cell that has a text value ("Y" or "N") and one that is counting days (45). How would I get the row to change to red if I have a "N" condition and a >21? Thank you for any help.
Hi Erik,
Try this formula:=AND($B2="N",$D2>21)
Where $B2 is the first cell of the Y/N column, excluding headers; and $D2 is the first cell of the Days column.
Thank you for the help. It works perfectly. I have over 140 rows. Is there a way to apply the formatting to work individually with each cell without having to manually go to each cell? Thank you again for your help.
Simply apply that rule to all 140 rows. Click Conditional Formatting > Manage rules, and change the range in the box under "Applies to". Since you use relative row references in the formula (without the $ sign), the rule will be applied to each row individually.
If suppose change the particular cell value from 5 to 3 etc.. now need to highlight color wherever we changed value
Hello Sabarish,
Do you mean you edit the cell manually and you want that cell to change the color once the value is changed? Do you want the cell to keep the color when a workbook is closed and then re-opened?
Wow, thanks a lot for those tips, it will help a lot!!!
THanks alot it helped!!
Hi, I work on rotation updates and i colour code them based on the stage they are for example if i have initiated the visa process then i colour them in Yellow and if they are on rotation - Green and so on. What i want to know is if i create a table as below
1 In Process
2 On the ground
3 Returned
4 Complete
And another table with the rotator details, i would want to automate the colours when ever i update the rotator details. For example : If i input 1 in Row A1 then i want the entire row to be coloured and if i input 2 in row A2 then it should coloured to a different colour. Is this possible with conditional formatting?
THanks for your help!
Hi Sudha,
You can select all the rows that you want to get colored (entire rows without column headers) and create several rules, a rule per each value in column A, with the following formulas:
Green: =$A1=1
Yellow: =$A1=2
etc.
Where A1 is the top-left cell of the selected range.
Hi, I need a formula to colour cells based on what I sell.
I have spreadsheet with a code for what I sell, so household HC, car PC and van GV at the start of the row.
I also have a few other things in the row, is there a way for colouring the row based on what I put in, so HC - blue row, GV - orange row?
Thank you
Hi Will,
Of course, you can do this. Simply select the entire table and create a separate rule for each code with the below formulas (assuming that your codes are in column A and row 2 is your top-most row with data):
Blue: =$A2="HC"
Orange: =$A2="GV"
HI..Is there a way where by i click on a cell which has any value and it changes it color...and also of copying value of cell into another cell in different spread sheet by clicking on it or any other manner.
Hi Rakesh,
Both of your tasks can be accomplished using VBA. But actually I do not see any point in writing a special macro for the first task since it takes just a click on the Fill Color button on the ribbon to color a cell.
Hi ablebits,
I am having trouble with the =SEARCH(“pine”, $E7)>0 formula described in this article, (I've adapted it to fit my criteria) it just doesn't work. I require the row ranging from E7 to H7 to change colour when 'pine' is in cell E7.
Cell E7 has numbers preceding the text, e.g '4.2 Pine'. Also, the cell contents are selected using a drop down box (via data validation). Will either of these affect the formula?
Look forward to reading your reply
Jon
Hi BSWjon,
Conditional formatting rules work with drop down list values as well as with normal values. Your formula is also correct, I've just tested it on similar data (drop box, preceding text) and it has worked perfectly. If you can send me your sample workbook at support@ablebits.com I think we will be able to figure out the cause of the problem.
Hi Svetlana,
I am struck at one point in my excel sheet, the client needs to detect all red colored cells in a column, and give them a code like "L" and copy in the corresponding empty row. I am not sure how I should move....
I am looking for your kind guidance in this regard.
Thanks
Shikha
Hi Shikha,
I think you can try filtering the column by color as explained in this article - How to filter cells by color in Excel and then copy the filtered cells.
hi...i have a data for product pricing let say from day 1-10. i want to read the data fast. for me to do that i want to see which items increase, decrease and retains the same from day 1 - 10. is it possible for conditional formatting? thank you.
Hello Mir,
I believe you can use Excel Icon Sets for this, e.g. three arrow set.
You could create an additional column with a formula that calculates the difference between Day 10 and Day 1, say =P2-G2 (where P2 is Day10 and G2 is Day1). Apply an icon set to this column and select the box "Show icon only".
Hello Svetlana,
I have a list of data start from January To December.
Data contains Month wise "Input Data" & "Target Data".
I want to change the color of the cell in "Input Data" if that particular month's "Input Data" less that the "Target data" for that month.
Also My target data for every month is changing.It starts from 0%,12%,24%...to 100%.
Can you please help me for that?
Please mail me your response on mail.
Thanks,
Mayur k.