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 made a table which uses a simple formula to calculate the profit of deposit money then shows the result. Each row stands for a day.And now, i want the row of containing current day result can be shown on screen automatically (something like a pop up message)when I logs in to my account.and afterward by clicking a button or icon whenever I wish. In summary I WANT A ROW OF DATA IN EXCEL 2007 BE SHOWN ON DESKTOP LIKE A POP UP WINDOW AT START UP.I hope I explained it clearly.
THANKS
Hi all,
How to send a specific excel data as a pop up message on desktop by these rules:
1- Auto pop up at start up
2- By user click
3- contents data varies based on computer current date.
Does anybody know How?
Thanks
It is very difficult or probably impossible to display a pop-up on desktop. You can get the dialog to appear in Excel upon opening a workbook and /or clicking a button in the workbook. The question is what exactly you want to write in that dialog?
Hi Svetlana
At first i should thank you for your helpful advice to clear my mind about some problems.
But now,i encounter another problem and hope i can describe it well.
1- I made a table that calculates the benefit of a deposit money then shows it in a cell(all in a row).It also highlights the row of current day "today()" nfo.
Since it has too many rows it takes time to find the right one, so i want to show the exact data based on current day in different place for example at the top of the sheet.
2- Is it possible to show this new row on screen when a user log-in. (something like pop up text ).
Thanks for your hints even if it doesn,t solve my pb.
Hello Morteza,
Thank you very much for your kind words! Regrettably, I do now know a way to show a certain row at the top of the sheet. Really sorry for not being able to help you.
Hi Svetlana
Thank you for you good work.
How do you change the color of a value in a cell that has changing (RTD) dynamic value:
Example:
Cell A1 contents 1000 Text color is BLACK time 00:01
Cell A1 contents 1001 Text color is GREEN time 00:02
Cell A1 contents 999 text color is RED time 00:03
Thank you
Ian
Hi Ian,
You can try to do this by creating 3 different rules of the type "Format only cells that contain" that apply to the entire table. Please see this example for step-by-step instructions: How to change a cell's color based on value.
Though, I have to say I have never tested the conditional formatting rules on data returned by an RTD and cannot say with confidence whether this will work.
thnx alot. this was very helpfull
Hi Svetlana,
how to highlight first order row of every client? My spreadsheet contains client name, date of acquisition columns and has many entries per client.
Many thanks!
Hi Marcel,
I cannot figure out a way to do this with conditional formatting. However, our Duplicate Remover add-in can help. You can download a trial version and then do the following:
1. Select your entire table, and click "Duplicate Remover" icon on the ribbon, then click Next.
2. Choose to find "Uniques +1st occurrence".
3. Select only your "Client ID" column as the key column.
4. Select the action "Fill with color", choose a color and click Finish.
The first order row of every client will be shaded with the color of your choosing. Is this what you are looking for?
Hi Svetlana,
I cannot set a conditional (color) format in (say) cell A1 based on A2 if A2 is a formula. If I type in a hard number into A2 then A1 goes red - it works fine - but when I put the formula back into A2(which delivers the correct answer itself for my spreadsheet)then A1 does not respond ?
Please help.
Many thanks
Owen
Hi Owen,
In theory, this should work with formulas too, unless you use something very specific. Could you give an example of your real formula, probably this will give me a clue?
Hi svetlana,
Have another query. Its related to Macro. I have two different work sheets. from the first sheet i have to copy two separate cells and have to paste that in the second sheet. after i paste i will get values generated in the second sheet. then i have to copy the generated values and paste it in the first sheet. this has to keep on goin on a loop. how to do this.
For example from first sheet i will copy distance and speed and paste in the second sheet. based on these values cost will be automatically generated in the first sheet. and then i have to copy these costs and paste in the first sheet. Then i have to copy next two values of distance and speed from sheet 1 and paste in sheet 2. this has to go as a loop.And the sheets should automatically open.
Chris
Hi Chris,
Sorry, I do not know a solution for this. Maybe you will be able to find the answer on these 2 forums:
https://www.excelforum.com/excel-programming-vba-macros/
https://www.mrexcel.com/forum/excel-questions/
thank you..
Hai Svetlana,
Thanks for your reply. Second part worked perfectly. But for the first part when i say start date as 20/03/2014 and duration as 2 days then it should consider 20th also. so the end date should be 21/03/2014.
Cheers
Chris
Hi Chris,
In this case, the correct formula is this =WORKDAY.INTL(A1-1,B1,7)
However, please note that if your start date as 20/03/2014 and duration as 2 days, the end date will still be 23th because March 21 and 22 are Fri and Sat, respectively, and they are days off according to your requirements.
Hi. Thank you for the helpful instructions. I am trying to set the color of a row based on the text in one column, but have a list of words to exclude.
Therefore, I want the rows where certain words do not appear in a specific column to be highlighted. I would greatly appreciate your help.
I have tried the following formula without success
=AND($F17"BLUE", "RED")
and
=OR($F17"BLUE", "RED")
Hi Abby,
If my understanding is correct, you need to highlight rows where neither "BLUE" nor "RED" appears in column F. If so, select your entire table and you can use create a conditional formatting rule with this formula (assuming that your table has headers and row 2 is your 1st row with data):
=AND($F2<>"RED",$F2<>"BLUE")
If you want to highlighted rows that contain certain words, let's name them "GooodWord1" and "GooodWord2", but do not contain words-exceptions, say "ExcludeWord1" and "ExcludeWord2", then you will need a very complex formula like this:
AND(false=ISERR(SEARCH("GooodWord1",$F2)), false=ISERR(SEARCH("GooodWord1",$F2)), true=ISERR(SEARCH("ExcludeWord1",$F2)),, true=ISERR(SEARCH("ExcludeWord2",$F2)))=true
As you see this formula is very long and that is why your workbook may start working a bit slower than usually.
How to use Conditional Formatting in total Row Like
Name Age City
Jaslok 20 Delhi
Ramesh 21 Jabalpur
Rama 22 Kanpur
Hi Pratap,
It depends on what exactly you want to do. If you can give me some more details about your task, I'll probably be able to help.
I am creating a template and I have queries in that. It’s in two parts.
First Part
I have a start date of a work. And the no of days the works is going on. In the next column I should get the end date. But it should add the weekends. (For example my works starting date is 13/03/2014 and the no of days of work is 2. Then the work ending date should come as 16/03/2014. (Weekend is Friday and Saturday. Not Saturday and Sunday). I tried using “workday” command but I think it assumes (Saturday and Sunday as weekends).
Task Name Start Date Duration End Date
Survey 13/03/2014 2 ?
Second Part
There are dates in the column. As per the start date and the end date that we have calculated from part 1 the cells should color automatically. Say if it the work is from 13 to 16th then the cells between these two dates should be automatically colored.
Start Date End Date 13 14 15 16 17
13/03/2014 16/03/2014
Can you help me to do this excel.
Hi Chris,
You can achieve the desired results in this way:
Part 1: Use this function =WORKDAY.INTL(A1,B1,7) Value 7 indicates Friday and Saturday as holidays. You can find the complete list of the weekend number values here:
https://office.microsoft.com/en-001/excel-help/workday-intl-function-HA010354380.aspx
Part 2: You can try creating a conditional formatting rule with this formula: =AND(D2>=DAY($A2),D2<=DAY($C2))
Assuming that row 2 is your 1st row with data, A2 is the start date, C2 is the end date, and D is the column containing "13 14 15 16 17".
Hi Svetlana,
I sent you an email.. hope we can get this solved.
Hi Steve,
I emailed you back the result.
The Search formulas work just fine, just make sure you use the first cell with data in the formula, which is D3 in your case:
=SEARCH("Passed", $D3)=1
=SEARCH("Annual", $D3)=1
Also, it is important that you enter the range with your data only under "Applies to" and not the entire column, otherwise the formula will be applied to the first 2 rows too and you will get incorrect results.
Hi Steve,
Select cells in Colum C that you want to format and create rules with these formulas (assuming that row 2 is your 1st rows with data):
Orange: =SEARCH("Annual", $B2)=1
Green: =SEARCH("Passed", $B2)=1
This should color cells in Column C when the corresponding cells in column B contain Annual and Passed, respectively. If you are looking for something different, please send me a sample workbook at support@ablebits.com and we'll try to figure this out.
Hi Svetlana,
I have 2 columns-- in one is the Event Name and the other is Event Type
I want the event name in column C to change color based on the 3 types of events I type in column B
so if you type Annual I want that event name to change Orange
if you type Passed I want that event name to change Green
My problem is its changing ALL of the events the colors because it contains the word annual..
please help!!
Hi Svetlana,
for my work i need to enter different values for each row every time.
i would like for the coloring of the new entry to be automatic to green.
and i want the previous record to be white again. meaning i want always the latest entry will be colored and the rest colorless.
is there an easy way to achieve this.
much thank,
Joe
Hi Joe,
This is not possible to achieve using Excel's conditional formatting. Our Excel specialist has written a small macro for you that shades the latest edited cell in green. You can try this solution by copying the macro to your worksheet:
Private Sub Worksheet_Change(ByVal rnUpdated As Range)
Static strLastUpdated As String
If strLastUpdated <> "" Then
Range(strLastUpdated).Interior.ColorIndex = 0
End If
rnUpdated.Interior.Color = CLng("&H00FF00")
strLastUpdated = rnUpdated.Address
End Sub
If you are not very comfortable with macros, this short tutorial may be helpful:
How to insert and run VBA code in Excel
I have a large spreadsheet that contains two date columns. One of the date columns is column F. I want to highlight every row that has the date 12/31/2013 in column F, but I can't make it work. Thanks!
Hi Katie,
The point is that Excel stores dates as numbers, starting from January 1, 1900. So, 1-Jan-1900 is stored as 1, 2-Jan-1900 as 2… and 12/31/2013 as 41639. To make the formula work, just enter your date in this numerical format, i.e. =$F2=41639 (assuming that row 2 is your top row with data).
Another way is to convert the date to the number format is which it is stored: =$F2=DATEVALUE("12/31/2013")
it is not helpful to me as no formula to change the entire row color is sucessful. i want to know how a row will be coloured if a value change. thanks
Regrettably, I'm not able to give any advice without knowing what exactly you are trying to achieve. If you can give an example of your data (including column names), we will try to work out a proper formula.