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 have a Question when we find any data in spreadsheet through Ctrl+F than that cell Present in a colour based how to use this query.
Hello,
I am trying to make each row change color if within a date range. For example, I would like a specific color for each month. If I type a January date it will be one color, but a February date would be another. I can't seem to figure out how to write the formula for the date range.
Thanks!
Lets say your dates are in column A. Click in that cell
Go to Conditional Formatting. New rule..
Use a formula to determine which cell to format.
Under formatting values. Type in =A1="January"
Click format and choose your color for that month. Say okay. The window will disappear.
Click again on conditional formatting and go to manage rules. First double click the rule. It should be something like = $A$1="January". Remove the dollar sign before the 1. Leave the 1 before the A. In the applies to change it to =$A$1:$last column letter $ lastrow number
Hello
I'm not sure if posted above, but I have one query.
I am using the conditional formatting formula to highlight a range of cells in a row based on a single cell.
I need to do this for 100+ rows. All the same range, but one row after another.
Instead of creating a new condition for each row and cell, can I copy this and apply to each row?
For example, cells B2 to J2 will highlight when K2 >0.
Can I copy this to apply to B3 to J3 when K3>0 and so on?
I would appreciate any help!
Many thanks :)
Chloe
You can usually do this if you use... when$k2>0... This tells it to always use column K. Continue conditional formula as normal.
Go back to conditional formatting to edit. Under your applies to change it to =$B$2:$J$100. (or whatever your final row is)
I found my error, so used to quotations for references. Just had to follow the directions, substitute my settings, and it worked. Thank you for the tip!
Yeah, I tried the conditional formatting based on an 1000 cell array where I need to highlight rows greater than a value. I even set the range for the values I wanted to check (in a single column, then highlighting the rows that cell is in where my established condition is true).
I've got nothing. I've got a separate count for the cells in that column where my same condition exists, and I know for sure it is correct.
Hi,svetlana
Greeting of the day
I want to formula for automotic bold for example..
we find something in our data, after find it become automatic bold or color in excel sheet ,plz help us
Hello Rajesh,
You can create a rule with the formula like this: =SEARCH("text", $A2)>0
And select "Bold" under the "Font style" on the "Font" tab of the "Format Cells" dialog.
I want a useful formula for colouring if a cell value is less or more than original cell value. example, Invoice value is 5000 in cell D cell colour green/white, if received amount is less than 5000 cell colour to be red.
pls reply.
krr sharma
Select column D and create two rules using the following formulas:
Green Rule: =IF(AND($F2<>"", $D2>=$F2)
Red Rule: =IF(AND($F2<>"", $D2<$F2)
Where F is the column with received amount.
HI,
I tried with this formula, not working, pls clarify formula If I received an amount entire row coloured by green, If received less than amount entire row should be red.
KRR Sharma
Hiii....
i want to get a formula & need your help...
if cell d1=fail, then color of cell a2 is blue..how can i do this?
Hi Nazmul,
Simply select cell A2 and create a conditional formatting rule using this formula:
=D1="fail"
Hi Svetlana,
I have a column of data that I will be adding to each day. It will occasionally be the case that the data I add will be a duplicate value already in the column above. Is there a formula in conditional formatting, that will highlight when this happens. Unfortunately using 'Remove Duplicates' or adding a filter is not sufficient as I just need the value highlighted straight away.
Would be great if you could help out.
best wishes,
George
Hi George,
Sorry for a big delay in response. Please see the following article, looks like this is what you need:
https://www.ablebits.com/office-addins-blog/how-to-highlight-duplicates-excel/
Hello Svetlana,
I tried to used the formula shown above, however when I change the dates in the cell to test the formula it does not make the necessary changes. Also, I want to express that I am using the conditionally formatting in a different column in which the dates are being used.
I have a simple need. I need some text in a cell to be of two colors. in "Ending balance: Actual/Budget", the word "Budget" has to be in a different color. When I alter the color on the spreadsheet the program keeps reverting it to black.
How can I do this?
Thanks,
Doug
Hello Everyone,
I have a report that I am attempting to use a conditional format to highlight a cell when the date which is locate in a different column is prior to 06/17/13. Can anyone assist me in sharing the formula to use.
Hello Toni,
Select the entire column with the dates you want to highlight (not including the column header, if any) and create a conditional formatting rule using this formula:
=$A2<"06/17/13 (where A2 is top cell).
Hi Svetlana,
What if you want to highlight an entire row using a color scale that applies to only one column? That is, in your first example at the top, you have a Qty column, and you could easily select conditional formatting -> color scales, and select the color scale of choice. But if you want to copy that color scale across the other columns, excel thinks you want to update your color scale with the values in those columns. So if you try copying the formatting from column c to column b, it will just turn column b green and column c red (or whatever color scale you've selected). I want to highlight ALL of the rows by the relative order quantities. Is there a non-vba solution for this?
Hi everyone
I have a list of names, ID's, dates and hours and I would like to colour the last hour each day by ID/name. How can I do that?
Thanks a lot!
E.g.
Name ID Date Hour
A 1 5/11 8AM
A 1 5/11 6PM (COLOUR THIS ONE)
A 1 6/11 8AM
A 1 6/11 12PM
A 1 6/11 2PM
A 1 6/11 6PM (COLOUR THIS ONE)
B 2 5/11 9AM
B 2 5/11 1PM
B 2 5/11 2PM
B 2 5/11 7PM (COLOOUR THIS ONE)
B 2 6/11 8AM
B 2 6/11 12PM
B 2 6/11 2PM
B 2 6/11 7PM (COLOUR THIS ONE)
I have a very large organizational budget spreadsheet with multiple columns for each month. So November has Primarily two columns and, let's guestimate, 500 rows. I want to set the second column of each month up to auto code red/green if it's more than the planned amount for that bill (listed in column A).
So picture Column A & B, 500 rows (technically still grouped out somewhat). Column A has ... Budget amt and Column B actual bill amt.
--This would be Col A-- --This would be Column B--
Nov Power Budget Amt Actual Bill
LA Power $2700 $2407.22 (Green)
Chic Power $1800 $2019.85 (Red)
NY $1200 $1407.25 (Red)
NewOrl Pow $1000 $859.36 (Green)
Seattle Pow $3500 $3895.67 (Red)
Miami Power $5000 $5262.98 (Red)
MemphisPowr $2000 $1709.24 (Green)
Denver Pow $4500 $4341.72 (Green)
Currently I create this massive 12 month spread at the beginning of the year and set conditional formatting by the (i.e.) budget limitation listed in Column A to code Column B. However, this changes as certain bills do fluctuate throughout the year (Power, gas, etc.).
I'm wondering if there's an easier way to do it? Such as Functions? And could I choose all of Column B above (while it was still empty of values) and set that whole section to 'format' appropriately as the values are entered by the line immediately to the left in Column A - without having to do it line by line? Groups are way better than 500 individual lines!
I am currently using Excel 2010. I have a spreadsheet where most of the cells have a VLOOKUP pulling numbers from a separate tab in the same workbook. I am trying to set the cells so that they will change to a yellow fill if their value is not the same as another cell, i.e. J5 not equal to S5; J6 not equal to S6, etc. If the number in S5 changes, I would like it to automatically change J5 to yellow. Currently, I can get J5 to change to yellow when I first apply the conditional formatting and S5 is a different number than J5, but if I change S5 to the same value as J5, it will not remove the yellow fill from J5.
Hello,
This is really strange. The following simple formula works perfectly for me:
It looks strange. There should be a simple formula in your conditional formatting rule:
=$S5<>$J5
Hello Svetlana,
It is possible to highlight current day from a calendar using conditional formatting.
Thanks in advance
Hello Poc,
Of course, you can do this using the following formula:
=$A2=TODAY()
Where A2 is the first cell with a date in the column.
Hi,
How can hightlight the Name as RED where amount is <5000.
Hi!
Select the names you want to color and create a rule with this formula:
=B2<5000
Where B2 is the first cell with data in the Amounts column.
Hi Svetlana,
thank you for your reply, I had actually resolved the problem and was about to inform you when I saw your reply.
The error was part my fault caused when transposing the simplistic example I gave you into the actual values I am using and the use of a semi colon.
Thank you very much for your assistance.
Paul
Thank You Svetlana,
I will try this and provide feedback.
Paul
Hi Svetlana, I have tried your proposed code but it does not appear to work!
The code for Blue is fine, however I cannot get the other two lines to work correctly!
When I enter each of the lines a prompt states that there is an error, I am using excell 2007, is there any other suggestion you can offer.
Thanks Paul.
Hi Paul,
I use Excel 2013, though it should not actually make any difference. The rules work just fine in my sample workbook.
The only possible reason that comes to mind is that you have a semicolon rather than comma set as List separator in your Windows Regional settings, which is the standard for European countries. You can check this in Control Panel > Region and Language > Additional Settings. If this is the case, then you have to replace all commas with semicolons in the formulas.
If this does not help, you can send me your workbook at support@ablebits.com, and we will try to figure this out.