Excel conditional formatting based on conditions - excel

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.

Related

How to count conditional formatted cell colors across a row

I have 5 cells that are conditional formatted. Column B is CF for 48 months and turns red on 48 months and 1 day, Column C is for 36 months, Column D is for 24 months, Column E is for 18 months, and Column F is for 12 months.
I would like to be able to use a count color formula to count the green color cells across the row (i.e., B1:F1) and place the result in H1. I have tried to use every VBA I could find but none of them work. For Example, when I use a COUNTConditionColorCells Function, it produces different number sequences next to the cell range box (see attachment) Thanks
Sample Worksheet
Function Argument

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

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.

Conditional formatting Excel results from cell, address functions

I am using the cell, address, index, and match functions in Excel to return the address of the intersection of a row and column match. I can get the address correct using the following function, but I can't get it to format using conditional formatting with a formula.
=a2=CELL("address",INDEX(A2:E6,MATCH("g",A2:A6,0),MATCH("c",A2:E2,0)))
The data looks like this and the upper left corner is in cell A2.
a b c d
e 1 2 3 4
f 5 6 7 8
g 9 10 11 12
h 13 14 15 16
I want to enter a formula that colors the matching cell a certain color (the "11", in this example). How do I get this to work? If I just type =a2=$D$5 in the conditional formatting formula, it works, but I can't get it to work using the formula above.
Try following. I tested and got correct formatting.
=CELL("address",A2)=CELL("address",INDEX($A$2:$E$6,MATCH("g",$A$2:$A$6,0),MATCH("c",$A$2:$E$2,0)))
This will also work if there is no duplicate values in range.
=A2=INDIRECT(CELL("address",INDEX($A$2:$E$6,MATCH("g",$A$2:$A$6,0),MATCH("c",$A$2:$E$2,0))))
Another way to do that
=CELL("address",A2)=ADDRESS(MATCH("g",$A$1:$A$6,0),MATCH("c",$A$2:$E$2,0))

Excel Conditional Formatting Formula

I am trying to make a column do this: so lets say
If the score of 4 is made from a 2 x 2 then it is green.
If the score of 4 is made from a 4 x 1 or a 1 x 4 then it is yellow.
I am done the formula for the green and the yellow but it only happens once. So if I change a 2 x 2 to 4 x 1. It will stay green. Not change to yellow.
Formula for Green (2x2):
=IF(G31=4,IF(D15=2,IF(F15=2,0,1),1),0)
Formula for Yellow (4x1, 1x4):
=IF(G31=4,IF(D15=4,IF(F15=1,0,1),1),0)
Please help me work this one out. Thank you.
enter image description here
Tried the formula but does not work, even if I remove every other formula:
enter image description here
Use a combination of AND and OR
Formula for Yellow (4x1, 1x4) =AND($G31=4, OR($D15=1, $D15=4))
Formula for Green (2x2) =AND($G31=4, $D15=2)
EDIT
As per your screenshot, if you are trying to change a range, not just cell G31, use the following:
Formula for Yellow (4x1, 1x4) =AND($G1=4, OR($D1=1, $D1=4))
Formula for Green (2x2) =AND($G1=4, $D1=2)
Change the number 1 for the starting row of your cells (3, 4, 5 whatever) and set the Range to be =$G$1:$G$100 again changing the 1 and 100 for your start and end row.
I cannot stress enough, if your data does not start in row 1, you will need to edit the above to suit your needs.

Conditional formatting in Excel based on formatted output in other table

Say,I have 2 tables...Tables are related...
1 3 5 7
8 8 9 10
11 12 13 14
&
2 3 5 5
1 1 1 1
3 4 4 4
I have highlighted top 5 values in first table using conditional formatting rules.Now I want to highlight cells in the second table based on first table...Assume 11 12 13 14 7 10 are highlighted in first table....I want to highlight cells in second table occupied same position as of in highlighted cells in first table..i.e. 3 4 4 4 5 1 should be highlighted...How can I do that
Use Excel functions RANK and/or COUNTIF to calculate a sequential ranking list column for the first table. The expression is explained here.
For the second table, you can then use conditional formatting based on the computed rank.
Might just be an elaboration of #Axel's answer and I agree the details of the question do not make sense but the position of a selection of top (or bottom) ranked cells in one array (say A1:D3) can be used to determine whether or not to format a cell in the corresponding position of another array (say H5:K7):
Select from H5 to K7, then HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=RANK(A1,$A$1:$D$3,)<6
Format..., select formatting, OK, OK.
Change the 6 to suit how many cells are to be formatted which for <6 could be more than five if the value ranked fifth is duplicated.

Resources