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
Hello Svetlana,
Thanks for your kind answer, I will try to find out more.
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.
Hello,
I will try it, thank you very much,
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!
I want the cell in column L to be highlighted yellow if any cell in that row says "Holiday Inn"
Thanks!
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.
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.
Hi Parameswar,
I am glad you've found it helpful. Thank you for your comment!
Hi Svetlana,
This is a very good post. It helped me to achive my formating I wanted.
Thnks a lot.
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!
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.
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.
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
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.
Hi Charlie,
Thank you very much! It's always a pleasure to get such comments :)
Hi Svetlana,
Just wanted to say thanks for this, it was really useful and helped me achieve exactly what I wanted.
Many Thanks,
Charlie
Hello John,
I think you can use the conditional formatting as demonstrated in this article, and copy one of the following formulas across the column in which you will enter specific text, where A is the name of your column:
For exact match: =$A1="your text"
For partial match: =SEARCH("your text", $A1)>0
You can find more details here.
If you need something different, please clarify. Thank you for your comment!
Hi Svetlana Cheusheva,
What if i wanted to highlight the row whenever there is different text across same column. In my excel i have more than 50 portfolio name and i wanted to highlight each portfolio name with one colour. For this formula," =SEARCH("your text", $A1)>0", "your text" is hard coded , any way to make this a variant?Thanks for you help!
Oh and I'm currently using Excel 2010 on Google Drive..
Hello Svetlana Cheusheva, how are you?
I wanted to ask if the question that was posted on November 28, 2013 is similar to my question.
I wanted to ask how to automatically highlight an entire row after entering specific text in a single cell within that row?
Please respond at your earliest convenience.
Thanks, John Lyons.
Thank you very much for such easy tips. Hardly took 10 mins opposed to writing magic VB scripts for days ;)
Hi Akshaya,
Using Excel formulas, it is not possible to substitute values in the original cells with data. However, you can create an empty column next to the column that contains the values you want to change and copy the following formula all across that newly added column: =IFERROR(IF(FIND("analytics",A1) > 0, "magic"), "_") where A is the name of the column with your original data.
please anybody comment here..
my question is
suppose i have a data like this
sas analytics developer
visual analytics using macro
msexcel is a spreadsheet program
Condition-:
Those values are containing "analytics" then change to "magic"
otherwise value should be "_".
Using Excel formulas...
Hi, I have a drop down box that changes sets of data in my array. It shifts between two sets of data depending on what's selected in the drop down box. I want one set of data to have one format and the other set of data to have a different format. When I use conditional formating, and I change the set of data once, the format changes correctly. However, when I change the data set back the format does not revert back to what it was originally. It is forever stuck in the new format.
Is it possible to do this with conditional formatting?
It is possible
Instead of condition formatting, simple If statement is to be used