If Index And Match - excel

I've got a function that uses If, Index, And, and Match. It is supposed to change the desired value when I toggle a built-in drop-down table that has 2 options ("good" and "bad"). If "good" is selected, the desired cell gives a result of "3". If "bad" is selected, I erroneously get an "N/A" error. I've racked my brain and all I can think of is there is some text/number issues with the match.. any suggestions? Here is the formula:
=IF(AND(MATCH(B2,$AO$2:$AO$31,0),MATCH("Good",$AU$2:$AU$31,0),C2="SG"),3,IF(AND(MATCH(B2,$AO$2:$AO$31,0),MATCH("Bad",$AU$2:$AU$31,0),C2="SG"),-5))

You can't use MATCH as a test on it's own because it doesn't return TRUE/FALSE, it returns either a number or #N/A error, so if there is no match the formula errors out, use ISNUMBER function wrapped around MATCH to return TRUE/FALSE as required in this situation, e.g. in place of your first MATCH use
=ISNUMBER(MATCH(B2,$AO$2:$AO$31,0))
...and the same for the other MATCH functions
...or you can use COUNTIF which will return a positive number (a match) or a zero (no match) e.g.
=COUNTIF($AO$2:$AO$31,B2)
In an IF function any non-zero number will equate to TRUE and zero to FALSE

Related

I have some problem with this excel formula =IF(A2:J2=O2,"Yes","No")

I am testing this if condition to whether O2 cell is matching with an element in A2:J2.
But the formula is displaying in the other 10 cells.
How can I get rid of this issue and execute the formula in only one cell?
Your criteria for the IF function: A2:J2=O2 is an array, which is the reason why it's spilling the values to the other cells. It's basically doing this: A2=O2 B2=O2 C2=O2 D2=O2 and so on..
And it returns all of the result of these. Therefore, you will have an array of results.
Maybe you want to consider this formula: =IF(ISNUMBER(MATCH(O2,A2:J2,0)),"Yes","No")
The match searches for O2 in A2:J2. If it finds the first match, it will return its position within the range. Otherwise, it will return an error. Therefore, we use ISNUMBER to check if the result of the match is a number. If it's a number, the ISNUMBER will return true. Otherwise, false. Then we'll use IF to capture the result of the ISNUMBER to return Yes if TRUE and No if FALSE.
Another way to solve this issue:
=IF(COUNTIF(A2:J2,O2)>0,"Yes","No")
this formula will count the content of cell O2 within A2:J2 and if available, it will return a number greater than 0.

Excel Match function with IF and OR Statement

Hi there , I have this formula
=IFERROR(IF(MATCH(A2,G:G,0)*OR(MATCH(B2,G:G,0)),"Present",),"Absent")
What I want is to return Present if one of the email from Column A and B present in Column G.
The Formula Work with *And but its not working with *OR.
If there is no match, then Match() will return the #N/A error, which will be multiplied with the other Match() result and still return an error. Therefore, this formula will only have a non-error result if BOTH Match formulas return a proper value. That's not what you want, I assume.
You need a formula or function that does not resolve in an error if there is only one match for the two conditions.
One option is to encase each Match into an Iferror. Anonther option is to use Countif, along the lines of this:
=if(countif(G:G,A2)+countif(G:G,B2),"Present","Absent")
Countif returns 0 if nothing is found or a count of the items found. The zero will equal a FALSE in the IF statement, so if neither Countif finds anything, the FALSE argument of the IF function will fire. Bit if any of the two Countif functions find a match, the result will be a number greater than zero, so the TRUE part of the IF function will fire.
I made a formula using match and isnumber.
=IF(ISNUMBER(MATCH(A2;G:G;0));"Present";IF(ISNUMBER(MATCH(B2;G:G;0));"Present";"Absent"))
So if match number is value that means there are match in column G so then it will return Present, simple as that.

Excel 2013 Conditional Formating NOT() operator does not seem to work

I'm puzzled by the following. I must be doing something wrong but can't see what.
This works
=FIND(A$6,CONCATENATE($A$2,$B$2,$C$2,$D$2,$E$2,$F$2,$G$2,$H$2,$I$2,$J$2,$K$2,$L$2,$M$2))
This doesn't work
=NOT(FIND(A$6,CONCATENATE($A$2,$B$2,$C$2,$D$2,$E$2,$F$2,$G$2,$H$2,$I$2,$J$2,$K$2,$L$2,$M$2)))
Everything is the same, the same range, the only difference is the NOT() operator that should change the condition from TRUE to FALSE and highlight the cells where the result of FIND() in not TRUE.
FIND function doesn't return TRUE or FALSE - it returns the position of the search value (a number) or #VALUE! error if the search value isn't present
It works as required in conditional formatting because any non zero numerical result is the equivalent of TRUE (and zero is FALSE)
Arguably it would be more understandable to use this version to return TRUE in conditional formatting if the search value is found:
=ISNUMBER(FIND(A$6,CONCATENATE($A$2,$B$2,$C$2,$D$2,$E$2,$F$2,$G$2,$H$2,$I$2,$J$2,$K$2,$L$2,$M$2)))
So for the reverse, you can use ISERROR function, i.e.
=ISERROR(FIND(A$6,CONCATENATE($A$2,$B$2,$C$2,$D$2,$E$2,$F$2,$G$2,$H$2,$I$2,$J$2,$K$2,$L$2,$M$2)))
Note: If you expect the value A6 to be equal to one of the A2:M2 values it might be easier to use COUNTIF for this, e.g.
=COUNTIF($A$2:$M$2,A$6)>0
and
=COUNTIF($A$2:$M$2,A$6)=0

Vlookup returns N/A despite of existing match

I have two tables, table1 and table2. I execute VLOOKUP function in order to fill in 3 columns from table2 into table1.
For some reason, the formula doesn't work for the first row, and doesn't find the exact match from table2 even though it exists.
I made sure that both columns (for comparison) have the same format (General) and there is no extra spacing. Same conditions also apply for the rest of the records, and it works there properly.
table1 - you can see the missing matches for the first row.
table2 - you can see the match does exist, but it is not reflected in table1.
Is there any other reason why VLOOKUP can't find a match for a specific record?
Try directly evaluating equality for the two cells that you believe are equal, for instance if A2 is the value you are looking up and Sheet2!A100 is the value you think should match try this in a cell:
=(A2=Sheet2!A100)
If that returns false then you know that there is some formatting issue or error in your vlookup.
Also try Formulas / Evaluate Formula ribbon command to step through your vlookup in case that highlights something wrong.
Okay - Here's a doozy of a use-case. VLOOKUP and INDEX-MATCH were returning #N/A for values that were "apparently" equal. Cleaned my data with =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) and that didn't work.
Then, I compared two cells that looked like they had matching values and they evaluated to FALSE (A1=B1 resulted in FALSE).
Then, as a last resort, I code checked each ASCII value for each character in the two cells and I found that the "-" in one cell was different from the "-" in the other cell. The first cell has the ASCII value 63 and the second cell had the ASCII value 45 for what looked like was the same "-". Turns out that 63 is a "short dash" and 45 is your standard dash or minus symbol.
The way to evaluate the ASCII codes for each character in a string is to combine the CODE function with the MID or RIGHT functions after testing the cells for length using the LEN function.
Examples:
LEN(A1) should equal LEN(B1)
For the first character in each cell:
CODE(A1) Code defaults to the first character on the left
CODE(MID(A1,2,1) yields the ASCII for the second character
CODE(MID(A1,3,1) yields the ASCII for the second character
and so on
If you have a lot of characters you can post an integer sequence next to your CODE-MID function and point the position argument to the related integer and just copy down or across
Or
You can look for the weird non-numeric character and just test that one for both cells.
Have observed scenarios like this where direct comparison fails (e.g. formula =A1=B1 resulted in FALSE) and yet length =LEN(A1)=LEN(B1) and letter by letter ASCI comparison (=CODE(A1,1,1), =CODE(A1,2,1), =CODE(A1,3,1), etc.) shows no difference.
What worked was to adjust the format of the lookup value inside the VLOOKUP.
e.g.
=VLOOKUP(A1, ARRAY, COL_NUM, FALSE) -> =VLOOKUP(TEXT(A1, "000"), ARRAY, COL_NUM, FALSE)
Here's an issue I encountered: my VLOOKUP formula returns the correct value (1) if I type in the value-to-look-up (1.016) directly in the formula, shown in cell F54.
However, if I referenced a value in column A as the value-to-look-up, the formula returned #N/A, as shown in cell F55.
(I was actually trying to VLOOKUP the current row's A value plus 0.015, i.e. VLOOKUP(A54+0.015, $A$3:$B$203, 2, FALSE))
Yet if I use the ROUND function, then the VLOOKUP formula works, as shown in F56.
I recently encountered the same issue and resolved it by changing the vlookup formula to =VLOOKUP([value to lookup], [lookup table], [column to return in the lookup table], False). Setting the last input argument to "false" forces Excel vlookup function to perform an exact match.

Explain LOOKUP formula

I'm trying to understand some legacy Excel file (it works, but I would really like to understand how/why it's working).
There is a sheet for data input (input sheet)and some code that is called to process data in the input sheet. I found out that number of rows in the input sheet is determined using a Lookup formula like this:
=LOOKUP(2;1/('Input sheet'!E1:E52863<>"");ROW(A:A))
"E" column contains names for import items and column is NOT sorted
"A" column does not contain anything special - I can replace it with B, C or whatever column and it does not affect the formula's outcome
According to what I have found about Lookup behaviour: •If the LOOKUP function can not find an exact match, it chooses the largest value in the lookup_range that is less than or equal to the value.
What does this ^-1 operation to the specified range? If E(x) is not empty -> it should turn into 1, but if it is empty - then it would be 1/0 -> that should produce #DIV/0! error...
1/('Input sheet'!E1:E52863<>"")
The outcome is the same, if I replace 2 with any positive number (ok, tried only some, but it looks like this is the case). If I change lookup value to 0, then I get #N/A error -> •If the value is smaller than all of the values in the lookup_range, then the LOOKUP function will return #N/A
I am stuck... can anyone shed some light?
LOOKUP has the rare ability to ignore errors. Conducting the 1/n operation will produce an error every time n is zero. False is the same as zero. So, for your formula, every empty cell produces an error in this calculation. All of those results are put in a vector array in the 2nd argument.
Searching for any positive value (the 1st argument) larger than 1 will result in LOOKUP finding the last non-error value in the above vector.
It also has the nice optional 3rd argument where you can specify the vector of results from which to return the lookup value. This is similar to the INDEX component of the the INDEX/MATCH combo.
In the case of your formula, the 3rd argument is an array that looks like this: {1;2;3;4;5;6;7;8;9;...n} where n is the last row number of the worksheet, which in modern versions of Excel is 1048576.
So LOOKUP returns the value from the vector in the 3rd argument that corresponds to the last non-error (non-blank cell) in the 2nd argument.
Note that this method of determining the last row will ignore cells that have formulas that result in a zero-length string. Such cells look blank but of course they are not. Depending on the situation, this may be precisely what you want. If, on the other hand you want to find the last row in column E that has a formula in it even if it results in a zero-length string, then this will do that:
=MATCH("";'Input sheet'!E:E;)
You might get some idea what the formula is doing (or any other formula) if you apply Evaluate Formula. Though since the principle is the same whether 3 rows or 52863 I'd suggest limiting the range, to speed things up if choosing Evaluate Formula. As usual with trying to explain formulae, it is best to start from the inside and work outwards. This:
'Input Sheet'!E1:E52863<>""
returns an array with a result for every entry in ColumnE from Row1 to Row52863. Since it is a comparison (<> does not equal) the result is Boolean - ie TRUE (not empty) or FALSE (is empty). So if only the first half of E1 to E52863 is populated, the result is {TRUE;TRUE;TRUE; ... and a LOT more TRUE; ... and FALSE ... and a LOT more ;FALSE and finally }.
Working outwards, the next step is to divide this array into 1. In arithmetic operations Boolean TRUE is treated as 1 and FALSE as 0, so the resultant array is {1;1;1; ... and a LOT more 1; ... and #DIV/0!... and a LOT more ;#DIV/0! and finally }.
This then becomes the lookup_vector within which LOOKUP seeks the lookup_value. The lookup_value you show is 2. But the array comprises either 1 or #DIV/0! - so 2 will never be found in it. As you have noticed, that 2 could just as well be 3, or 45 or 123 - anything as long as not a value present in the array.
That (not present) is necessary because LOOKUP stops searching when it finds a match. The fact that there is no match forces it to the end of the (valid) possibilities - ie the last 1. At this point, in my opinion, it would be logical to return "not found" but - I suspect merely a quirk, though very convenient - it returns that 1 - by its index number in the list, ie 52863 if all cells in E1:E52863 are populated.
Although the result_vector (Row(A:A)) is optional for LOOKUP it is required in this usage in effect to fix the start point for the index (effectively Row1, since an entire column). You might change that to say A3:A.. and the result would be the number of the highest populated row number in ColumnE plus 2 (3 -1).

Resources