Excel: Conditional formatting of whole row based on column value does not work - excel

Suppose I have a simple dataset in Excel:
Column 1 Column 2
A 1
B 1
C 2
D 4
E 5
F 9
Now I want to mark the whole row with green color, if the value in column 2 is larger than 3. I apply a conditional format with the formula =$B2>3 applied on range =$A$1:$B$7 and it does not work:
One line where the value is 2 is marked green and one where it is 9 is not marked.
Now I want to mark the row, however only, if the value in column 2 is between 3 and 6. I apply the formula =AND(3<$B2;$B2<6) to the same range and it does not work:
Nothing is marked green.
Where is my mistake?
Update:
I now also tried =AND(3<$B1;$B1<6), but still nothing is marked green?

Change =$B2>3 to =$B1>3 which should work for you.
Your formula start range and apply start range must be same. Otherwise CF will highlight different cells.

Related

excel365 - Conditionally format rows based on two string values?

Excel noob here. Lets say I have a sheet.
.
A
B
C
D
1
Adam
3
No
No
2
Betty
13
Yes
No
3
Chris
12
No
Yes
4
Dave
0
Yes
Yes
5
Emma
1
No
I want to conditionally highlight cells in multiple ways:
if column C and column D both contain the word 'Yes' colour the row green (e.g. match row 4)
if column C and column D are not the same, colour the row yellow (e.g. match rows 2,3)
if column C or D are empty, colour the row red (e.g. match row 5)
I set up two worksheet conditional formatters
=AND(SEARCH("Yes",$C2)>0,SEARCH("Yes",$D2)>0) is set to be green
=$C2<>$D2 is set to be yellow
=OR(ISBLANK($C2),ISBLANK($D2)) is set to be red
However, I'm getting mixed results. I get green rows where C and D are No or where C and D are different. I don't get any formatting for the second or third rules.
I tried just matching column values directly; =$C2="Yes" doesn't match, hence resorting to SEARCH.
Your observed behaviour is because of the commonality between rules 2 & 3, i.e. if C2 differs from D2 then it is, superficially, because the content of those cells differ but, if one of the cells is blank, when the other isn't, then both rules 2 & 3 are satisfied simultaneously.
In the screenshot below, I have made the assumption that 'half-blank' rows are to be identified before 'non-equal' rows:
the formula for 'equal' rows is
=AND(COUNTIF($C1,"*Yes*"),COUNTIF($D1,"*Yes*"))
(COUNTIF() is used because it caters for Yes being found within a longer string of text and, if not found at all, will return 0, which is interpreted, inside the AND() function, as FALSE, whereas if Yes is found then the function will return 1, interpreted as TRUE)
Given the non-independence of your rules 2 & 3 it is important that the rules implemented are prioritised as illustrated in the screenshot, which can be achieved by using the up and down buttons (highlighted) to move the currently-selected rule either up or down.

Excel conditional formatting based on conditions

I am working on a personal project and have spent many hours researching colour formatting based on conditions. Unfortunately I have not been successful in achieving the end product.
I would be very grateful if anyone could help write a VBA code to address what I am trying to achieve below.
I have one named SaisieSO and two ranges. Range 1 (C:H) in which I enter six numbers and range 2 (N:R) in which I enter 5 numbers.
I would like in the worksheet in the Range (C: H) the cells to change colour based on the following conditions:
any cell in range (C:H) to be coloured red with white font if their value is equal to the value in N
any cell in range (C:H) to be coloured orange with black font if their value is equal to the value in O
any cell in range (C:H) to be coloured yellow with black font if their value is equal to the value in P
any cell in range (C:H) to be coloured blue with black font if their value is equal to the value in Q
any cell in range (C:H) to be coloured orange with black font if their value is equal to the value in R
I would like each time I add a new row with numbers in both ranges for the VBA code to colour the relevant cells as stipulated above.
Example
Range (C:H) six numbers Range (N:R) 5 numbers
Dates
C D E F G H N O P Q R
02/08/2019 16 14 11 5 15 7 4 8 6 3 7
07/08/2019 12 6 2 14 1 5 12 6 15 5 13
08/08/2019 14 10 7 6 13 8 14 10 12 7 9
09/08/2019 8 16 6 10 7 2 7 16 2 8 4
I hope you are able to provide me an answer
Many thanks in advance
Bruno
I'm advising you not to use VBA, but to do this using conditional formatting, the basic feature of Excel, as explained in this URL.
You can simply write a formula, and when this formula gives "TRUE", then the conditional formatting will be applied.
E.g. in cell C2 I've put a value, and in cell N2 I've put the same one. I've then created a conditional formatting rule, based on this formula:
=(C2=$N2)
When C2 equals N2 the result of this formula yields "TRUE", so the conditional formatting will be applied.
Why the dollarsign in front of column N? Well, you seem to want to use conditional formatting for the range C:H. When you drag to the right (e.g. for column D), your formula changes into:
=(D2=$N2)
As you see, dragging to the right changes your column reference from C to D, but the N is left fixed, because of the dollar sign. This is known as absolute cell referencing, and is explained here.

Input data into a 2nd cell, based on the value of a 3rd cell? (Like "conditional formatting")

B1 is a checkbox. If checked B1=1. A1 can range from 0 to 10. If B1 is checked I want A1 to automatically = 10. Exactly like conditional formatting would turn it green. I cant put the formula =IF(B1=1,10,"") into A1 though because I need to be able to input other values in A1 without erasing the formula. I need to be able to reuse the sheet multiple times.
Ex.
A B
1 10 x
2 9
3 10 x
4 4
As Scott commented, you'd need to use VBA to do exactly what you're asking. A work-around, though, would be to add a third column with:
=IF(B1="x",10,A1)
In this case, Column A would be the user-inputted number, Column B would be your "x", and Column C would give the final output: 10 if B has "x", and the number from A otherwise.

Excel formatting/Highlight row based on the last date and equal cell value

My question relates with the following.
I have a matrix in Excel of values, I want to highlight the entire row if two conditions are met. Those conditions are:
a. For equal values on column A compare its date;
b. If the value is equal, highlight the row with the most recent date.
Graphically its the following:
A B
1 Y 04-08-2006
2 X 02-07-2008
3 X 12-05-2014
4 Z 09-08-2014
5 X 25-06-2016
6 Z 01-04-2018
7 Y 24-07-2018
8 X 25-09-2018
I want to highlight the 6, 7 and 8 row with different colors.
Can I do that with conditional formatting or its not possible and the only way is to write code in VBA?
Thank you.
You don't need VBA for this. Make a small Pivot table where your column A is the rows and columns B are the values set to max. Then add a columns that is a vlookup to add the max date for each group (formula show in image) and finally just add conditional formatting, one rule per group again as shown in the image (note in this case the formatting is applied to the range A1:C9
You can always hide column D and the pivot table or put them on another sheet if need be.

Compare in two columns and add value

I have 2 columns looking like this:
Column 1 Column 2
1 x
x 2
2 2
x x
1 2
I want to do two things;
For each row match (row n column 1 = row n column 2) it should mark cell n in column 1 green if there is a match and red if it is not.
It should create a sum cell where each match is worth 1 point, in this case column 1 should result in 2 points.
Is this even possible with excel and if so, how is it done?
For the first part of your question:
It should mark cell n in column 1 green if there is a match and red if it is not
You can do this using Conditional Formatting.
Ex:
Assume column A and column B, with the values starting in row 2.
The following conditional formatting would highlight column A values in green if they match the corresponding value in column B in the same row, otherwise red.
Highlight the values in column A, then apply this conditional formatting.
For the second part of your question
It should create a sum cell where each match is worth 1 point, in this case column 1 should result in 2 points
The following array formula will tally all the matches and show you how many there are:
=SUM(IF(A2:A6=B2:B6,1,0))
Assuming again that we are in columns A & B with your sample data.
Remember to commit this formula using Ctrl+Shift+Enter.
Per comment from andy holaday, here is another formula that will work:
=SUMPRODUCT(N(A2:A6=B2:B6))
or
=SUMPRODUCT(--(A2:A6=B2:B6))
These are not CSE formulas so you would not need Ctrl+Shift+Enter to commit them.

Resources