excel365 - Conditionally format rows based on two string values? - excel

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.

Related

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.

Excel mapping and create a new column

Excel file columns:
A B C
2 two 3
5 five 8
3 three 10
8 eight 11
12 one 15
I want to create a new column Din same file like below:
A B C D
2 two 3 three
5 five 8 eight
3 three 10
8 eight 11
12 one 15
I want to map C and A and if there's a match D takes values of B.
Example: Value 3 in C is present in A, so D will take corresponding B value three.
Thanks!
So building on BigBen's additional suggestion of using an IFERROR, I believe you want something akin to this in Column D:
=IFERROR(VLOOKUP(C1, A:B, 2, FALSE), "")
... and then drag down the formula throughout Column D
Now, there are some assumptions being made here:
Your data does not have any header row, ala the data starts in Row 1, not Row 2
You want empty/blank values where there is no exact match (this is BigBen's IFERROR suggestion). Your current question layout seems to suggest this. Otherwise, you'll get #N/A in all those blank cells in Column D.
EDIT: To confirm, I used your data (though I started in Row 2), and here's how it looked after -
If one has DA-functionality you could use:
1) - Excluding empty cells using FILTER:
Formula in D1:
=FILTER(B1:B5,COUNTIF(C1:C5,A1:A5)>0)
2) - Including empty cells using XLOOKUP:
Formula in D1:
=XLOOKUP(C1:C5,A1:A5,B1:B5,"")
If one does not have access to DA-functionality you could use:
1) - Excluding empty cells using INDEX, MATCH and SMALL:
=IFERROR(INDEX(B$1:B$5,SMALL(IFNA(MATCH(C$1:C$5,A$1:A$5,0),""),ROW(A1))),"")
Note 1 - This needs to be array entered through CtrlShiftEnter
Note 2 - Alternatively, one could use a non-array entered approach including AGGREGATE as per #basic: =IFERROR(INDEX(B$1:B$5,AGGREGATE(15,6,MATCH(C$1:C$5,A$1:A$5,0),ROW(A1))),"")
2) - Including empty cells using VLOOKUP:
Please refer to the other answer given by #Gravity here.
Basically the difference between both approaches could be vizualised like:

Excel - Formula or Macro to fill a cell based on another cell that links to yet another cell

In Excel, I am trying to make a cell based of the values contained in two other cells.
I need Cells X and Y to have data based on Cells L and #, like so....
X Y L 1 2 3 4 5 6
A 6 1 1 6;1 6;1 7;1 7;2 7;2 8;1
B 7 2 4 6;1 6;1 7;1 7;2 7;2 8;1
So row A, has columns X and Y filled based of the values in the number columns. The specific number needed is what is filled in in column L.
I am not sure the best way to phrase this question. If my example doesn't make sense, I can try to clarify or provide more examples.
I have no idea if this can be done with fancy formulas or with a VBA macro or two. I am an excel noob.
If I've understood your question correctly you can do this with a combination of Left/Right, Index and search.
In my example images, the user inputs their value in column D, and then columns B and C use the formulea
=LEFT(INDEX($F2:$K2,1,$D2),(SEARCH(";",INDEX($F2:$K2,1,$D2))-1))
=RIGHT(INDEX($F2:$K2,1,$D2),(SEARCH(";",INDEX($F2:$K2,1,$D2))-1))
respectively
Here, the Index function returns the correct column to look at (i.e. the value chosen by the user, the Search function finds the position of the semi-colon, and the left/right functions return the values either side of the semi-colon.

Excel vlookup with two columns in source and target returning another column

I have a spreadsheet that has 4 columns sheet 1, and 5 columns sheet2 and I need to do a vlookup on Sheet1!a2&c2 and match the row in sheet2!a2&c2 and return sheet2!c5.
I think Index and Match would do it but all the examples have been matching a single value to an array which isn't what I need for eg.
Can't do attachments yet :( text it is sorry for the format
Sheet1
R1 A B C D
R2 2 D 3 Result will match sheet1!a2&c2 to sheet 2!A3&C3 and return Sheet2!e3 ie 34
Sheet2
R1 A B C D E
R2 2 F 5 GR 72
R3 2 X 3 FR 34
Any links or help?
Update
Sorry I wasn't clear I want to match the cobination of A2 and C2 in sheet 1,
ie in the example =sheet1!A2&sheet1!c2=23
to the values in sheet2!a2 plus sheet2!c2,
ie in this example =Sheet2!a3&Sheet2!c3=23,
and then return the value in Sheet2!E? , ie Sheet2!E3=34 here
I've done this before by creating a cheat column in sheet 2 = a2&c2 in say d2 and filling down then using, assuming 3 rows, however I can't create the cheat column in sheet2
=vlookup(a2&c2,sheet2!d2:e3, 2, false)
The rows sheet2! look like, sorry about the formatting
Picture attached, which I suddenly got to do , where I need to match the yellow columns in the lookup then return the brown column to sheet1!E2 but I can't add the cheat column Sheet2!d2:3 to the sheet cause the user is difficult :)
Thanks again. Any good tutorial on Index?
Try using LOOKUP like this
=LOOKUP(2,1/(A2=Sheet2!A$2:A$10)/(C2=Sheet2!C$2:C$10),Sheet2!E$2:E$10)
The two "tests", i.e.
(A2=Sheet2!A$2:A$10)
and
(C2=Sheet2!C$2:C$10)
return "arrays" of TRUE/FALSE values but when you divide 1 by one of those and then the other TRUE is converted to 1 and FALSE to 0 so you get a resulting array of either 1s (where both conditions are TRUE) or errors [#DIV/0!] where one or both are FALSE.
When you lookup 2 in that array it will never be found so it matches with the last 1, i.e. the match is with the last row where both conditions are satisfied...and the corresponding value from Sheet2!E$2:E$10 is returned. Another way is like this:
=INDEX(Sheet2!E$2:E$10,MATCH(1,(A2=Sheet2!A$2:A$10)*(C2=Sheet2!C$2:C$10),0))
which requires "array entry" with CTRL+SHIFT+ENTER

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