How do I test for multiple conditions using Excel.
For Example:
I have Text in A2 'foo' and for each cell in column A:A that has 'foo' I want to Match B2 'Bar' to each cell in Column B:B. If the cell in A3 contains 'foo' and B3 contains 'bar', output "Match", Else "NA"
I have tried =IF(AND(A2=A:A,B2=B:B),"Match","NA"), but it does not work properly.
Try using COUNTIFS:
=IF(COUNTIFS(A:A,A2,B:B,B2)>1,"Match","NA")
Your idea was almost correct but faced the fact that the AND and OR operator in Excel are not array friendly, and also the fact that you already have a match on the line you are checking, so you need to have "more than 1" matches.
Related
I'm trying to count the number of cells in a row that contain "valid" values. There are many criteria for the value to be valid. So far I have this:
COUNTIFS(INDEX(S2ScoresAssQ1,ROW()-4,0),"<>",S2UnitSelectorQ1,"<>2",S2CodeAssQ1,O$2)
but cells that meet all of the requirements and contain formulas that evaluate to "" are still being counted, when they should not be. In other words, some of the cells contain this formula:
=IF(H5<>"",H5*I$3/H$3,"")
If that evaluates to a number, it should be counted. If it evaluates to "", then it should NOT be counted. ISNUMBER would work, but I don't know how to put that inside the COUNTIFS.
Here is an example:
Cell F4 should display '1', since there is only one valid 'A' assignment. The code in column F (cell F3) is:
=COUNTIFS(B$2:E$2,F$2,B3:E3,"<>")
The code is column E (cell E3) is:
=IF(ISNUMBER(D3),D3/12,"")
As Tom Sharpe said, using:
=COUNTIFS(B$2:E$2,F$2,B4:E4,"<>*",B4:E4,"<>")
works in the example, with "<>" eliminating the truly blank cells and "<>*" eliminating the cells that contain formulas that evaluate to "" (while leaving the formulas that evaluate to a number).
I was able to solve the problem in my original code using SUMPRODUCT():
=SUMPRODUCT(--ISNUMBER(INDEX(S2ScoresAssQ1,ROW()-4,0)),--(S2UnitSelectorQ1<>2),--(S2CodeAssQ1=O$2))
I'm comparing two columns matching a cell value in "P26" and if i find a match, output that value in the second column to the current cell i have this formula in. This formula works, I was wondering if there is a way to find a wildcard match from my value P26 lets say "1234*" instead of just a exact match "1234" ? Something like match "like" P26?
columns look like this, P26= "3 OK" <--- the "OK" is the wildcard part. i need to match the "3" in column 1 then output column 2 to the cell value.
1 12345
2 64578
3 56465
This formula is in a cell value:
=IFERROR(INDEX(AF4:AF31,MATCH(P26,AE4:AE31,0)),"---")
Use an Array formula like this:
=INDEX(B1:B5,MATCH(TRUE,ISNUMBER(SEARCH(A1:A5,D1)),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
In B2 I have text to search within, in C2 I have this formula to search for words on a worksheet called "keywords" to match against.
{=
IF(B2="","",
IF(ISNUMBER(SEARCH(keywords!$B$2:$B$5,B2)),"Fruit",
IF(ISNUMBER(SEARCH(keywords!$C$2:$C$5,B2)),"Nature",
IF(ISNUMBER(SEARCH(keywords!$D$2:$D$5,B2)),"Vehicle",
"no match"))))
The formula is only using the first keyword in B2, C2, D2 on the keywords worksheet, and not through B5, C5, D5. What is the correct formula?
I understand the result will be the last satisfied statement if more than one match is found. Please help!
formula
keywords
For a non CSE array use sumproduct:
=
IF(B2="","",
IF(SUMPRODUCT(ISNUMBER(SEARCH(keywords!B$2:B$5,$B2))*1)>0,"Fruit",
IF(SUMPRODUCT(ISNUMBER(SEARCH(keywords!C$2:C$5,$B2))*1)>0,"Nature",
IF(SUMPRODUCT(ISNUMBER(SEARCH(keywords!D$2:D$5,$B2))*1)>0,"Vehicle",
"no match"))))
For a slightly shorter formula that uses the title row on the keywords sheet as the return value, so no need to hard code the values. Use this:
=INDEX(keywords!$B$1:$D$1,AGGREGATE(15,6,(COLUMN(keywords!$B$2:$D$5)-COLUMN(keywords!$B$2)+1)/(ISNUMBER(SEARCH(keywords!$B$2:$D$5,B2))),1))
The ranges can be expanded to allow for more rows or columns in the future, without the need of adding more IF statements.
Try:
{ =
IF(B2="","",
IF(MAX(IFERROR(SEARCH(keywords!$B$2:$B$5,B2),0))>0,"Fruit",
IF(MAX(IFERROR(SEARCH(keywords!$C$2:$C$5,B2),0))>0,"Nature",
IF(MAX(IFERROR(SEARCH(keywords!$D$2:$D$5,B2),0))>0,"Vehicle",
"no match")))) }
The issue is that the search within your formula is looking a for a single value to search for within a specified text string therefore when you select the range $B$2:$B$5 it selects the value in the first cell of the range of cells.
Rather then using the SEARCH function use MATCH function with a Match Type of 0 for and exact match. NOTE: this does not need to be an array formula.
Example:
=IF(B2="","",IF(ISNUMBER(MATCH(B2,keywords!$B$2:$B$5,0)),"Fruit",IF(ISNUMBER(MATCH(B2,keywords!$C$2:$C$5,0)),"Nature",IF(ISNUMBER(MATCH(B2,keywords!$D$2:$D$5,0)),"Vehicle","no match"))))
Also your statement "I understand the result will be the last satisfied statement if more than one match is found. Please help!" you may have meant the first satisfied not the last; which would be correct.
I'm trying to make in excel a cell that every time you write something above that cell, it finds the text you typed in a specific column and returns the value of the cell that's next to it. Example:
Derp <---I type the word "Derp" here
1246.53 <--this returns the value next to "Derp" that found in the cells below
Names Values
X 173
ZN 5345
Q 76578
Derp 1246.53 <---returns this
AyyLmao 0.5
I already tried using Find and Match but they return some other values so I'm not sure what to do.
Assuming these values are in cells A1:B6, you can do: VLOOKUP("Derp", A2:B6, 2, FALSE).
A better habit would be to place the item you are lookup up, in this example, "Derp" in a different cell, say, D1. This would allow you replace the formula with VLOOKUP(D1, A2:B6, 2, FALSE) and allow you to type any name/value in D1.
Even better, you can make your formula more readable and dynamic by using Named Ranges. That is, name A2:B6 lookup_tbl and name D1 item_to_lookup and you replace the formula with VLOOKUP(item_to_lookup, lookup_tbl, 2, FALSE).
How can I simplify this with VLOOKUP or LOOKUP?
IF(OR(A1=1,A1=2,A1=3,A1=4,A1=5,A1=6,A1=7),"Yes","No")
is there any way to make it more robust using VLOOKUP or any other Excel function to avoid this many or conditions?
Basically that OR condition is the same as A1<8 so just do that and get rid of the OR.
=IF(A1<8,"Yes","No")
in this example i have a list in Sheet 2 in the A column that contains all the values. In sheet 1 in cell A1 I enter the test number and you can put this formula in any cell you want
=IF(LOOKUP(A1,Sheet2!A:A,Sheet2!A:A)=A1,"Yes","No")
A bit better:
=IF(ISERROR(FIND("|"&A1&"|", "|1|2|3|4|5|6|7|")), "No", "Yes")
Assumes no one ever puts "|" into A1
This is the same:
=IF(AND(A1>0,A1<8,INT(A1)=A1),"Yes","No")
If I'm understanding correctly, you have a value in cell, say A1, and a variety of other values in cells B1:B8 and you'd like to know whether A1 matches any value present in B1:B8.
You could set up a flag variable taking value 1 if a match is found and 0 if not as follows:
=1-ISNA(MATCH(A1,B1:B8,0))
Alternatively, you could do something like:
=IF(ISNA(MATCH(A1,B1:B8,0)),"No","Yes") to output something more similar to the above.