I want to perform a search on column 2 to find keywords that are missing in Column 1. I used the formula =IF(MATCH(G2,$E$2:$E$117,0),1,"No") so for rows that return 1, it means that the keyword exists in column 1. When a keyword in Column 2 cannot be found in Column 1, my formula will return #N/A. (Image attached)
However, I would like to understand whether this can be done in a much simpler way, perhaps using vlookup function? If so, how?
I am also unsure about the difference between this formula and the vlookup.
Hope someone experienced with Excel functions could explain it to me. Thank you in advance.
Cheers.
MATCH returns the relative location of the value in the range, while VLOOKUP will return the value.
When using MATCH wrap it in ISNUMBER to deal with the fact that if not found the MATCH will return an Error:
=IF(ISNUMBER(MATCH(G2,$E$2:$E$117,0)),1,"No")
Now instead of an error you will get No in the field when not found.
Another method would be to use COUNTIF:
=IF(COUNTIF($E$2:$E$117,G2),1,"No")
Although shorter, it will be slower than the MATCH version. It may not be noticeable with the limited data set but too many(10,000+) will cause problems.
To use VLOOKUP:
=IF(ISERROR(VLOOKUP(G2,$E$2:$E$117,1,FALSE)),"No",1)
This would be the perfect occasion to try the Brand NEW
XLOOKUP (wooo)
XLOOKUP is different from VLOOKUP in that it uses separate lookup and return arrays, where VLOOKUP uses a single table array followed by a column index number.
Syntax
=XLOOKUP (lookup, lookup_array, return_array, [not_found], [match_mode], [search_mode])
Arguments
lookup - The lookup value.
lookup_array - The array or range to search.
return_array - The array or range to return.
not_found - [optional] Value to return if no match found.
match_mode - [optional] 0 = exact match (default), -1 = exact match or next smallest, 1 = exact match or next larger, 2 = wildcard match.
search_mode - [optional] 1 = search from first (default), -1 = search from last, 2 = binary search ascending, -2 = binary search descending.
Related
"The range where the lookup value is located. Remember that the lookup value should always be in the first column in the range for VLOOKUP to work correctly. For example, if your lookup value is in cell C2 then your range should start with C."
But sometimes I want to be able to do dual-direction lookups. Ie, lookup using a key in column A to get the value in column B AND at the same time, in other formulas, lookup the value in B to get the value in A.
The only way I know is to add a column C which mirrors A, then use AB for the first lookup, and BC for the second lookup. But there has to be some cleaner solution. Is there some way to force VLOOKUP to use a different column other than the first one to find the key value, or is there a different function that would allow the equivalent?
As a side note, I am asking about Excel, but I actually use LibreOffice. Presumably the functions should be identical, but an answer that also works in LibreOffice would be preferable.
INDEX/MATCH will do it any direction of search.
So for your example of B --> A:
=INDEX(A:A,MATCH(yourCriteria,B:B,0))
The MATCH returns the row number of the match. The third Criterion of 0 is optional. The 0 is the same as FALSE for the forth criterion of VLOOKUP, in that it looks for an exact match.
The default is 1 with the data sorted it will return the match that is less than or equal to the criteria Like VLOOKUP's TRUE.
From that the INDEX finds and returns the correct value.
With the introduction of the Dynamic Array formula XLOOKUP we can use:
=XLOOKUP(yourCriteria,B:B,A:A,"",0)
I am using Formula as:
=INDEX(B1:G1,H3)
Its not working. even tough similar posts are present I could not find the issue with this.
I am actually doing a max of all the Row entities like:
=MAX(B2:G2)
and doing
=INDEX(B1:G1,H2)
It works for first row and not for the other
INDEX wants the relative position not the value. You need to add a MATCH:
=INDEX($B$1:$G$1,MATCH(H2,B2:G2,0))
The Match will return the relative position of the match.
Index is using H3 to determine the column to return. That is why Row1 is functioning. It is finding column 6 (between B1:G1) and returning the result. It is only happenstance that it is the correct answer. If you were to substitute 5 into cell H2 it would likewise return Column5. In the other examples shown, the max function is returning a column index which is beyond what is in the array (B1:G1 is 6 columns long).
To correct, pair Index with the Match function. Match will search the array (B2:G2; B3:G3; etc.) and return the column number of the matching column, then pass that on to the Index function to return the proper result.
Your final formula will look like this:
=INDEX($B$1:$G$1, MATCH(H2, B2:G2, 0))
I have an Excel file with 2 sheets - one sheet contains my items, prices, codes, etc. and the other sheet is for cross-matching with competitors.
I've included an Excel file and image below.
I want to be able to generate my code automatically when manually entering any of my competitor's codes. I was able to do INDEX/MATCH but I was only able to match with one column (I'm assuming they're all in one sheet to make it easier). Here is my formula:
=INDEX(C:C,MATCH(K2,E:E,0)
So this is looking only in E:E, when I tried to enter a different column such as C:C or D:D it returns an error.
I tried to do the MATCH as C:G but it gave an error right away.
The reason why match gave you error is because it's looking for an array and you put in multiple columns.
There is definitely a more elegant way to do this but this is the first one that I came up with.
=IFERROR(INDEX(B:B,MATCH(K2,C:C,0)),IFERROR(INDEX(B:B,MATCH(K2,D:D,0)),IFERROR(INDEX(B:B,MATCH(K2,E:E,0)),IFERROR(INDEX(B:B,MATCH(K2,F:F,0)),IFERROR(INDEX(B:B,MATCH(K2,G:G,0)),"")))))
Index/Match Combination
Please try this formula:
{=INDEX($B$2:$B$5,MATCH(1,(K2=$C$2:$C$5)+(K2=$D$2:$D$5)+(K2=$E$2:$E$5)+(K2=$F$2:$F$5)+(K2=$G$2:$G$5),0))}
Instruction: Paste the formula {without the curly brackets} to the formula bar and hit CTRL+SHIFT+ENTER while the cell is still active. This will create an array formula. Hence, the curly brackets. Please take note though that manually entering the curly brackets will not work.
Description:
The INDEX function returns a value or the reference to a value from within a table or range.1
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range.2
Syntax:
The INDEX function has two forms—Array and Reference form. We're going use the Reference form in this case.
INDEX(reference, row_num, [column_num], [area_num])1
MATCH(lookup_value, lookup_array, [match_type])2
Explanation:
To simplify, we're going to use this form:
INDEX(reference, MATCH(lookup_value, lookup_array, [match_type]))
The INDEX function returns a value from the reference My code column (B1:B5) based on the row_num argument, which serves as an index number to point to the right cell, and we're going to do that by substituting row_num with MATCH function.
MATCH function, on the other hand, returns the relative position of a value in competitorn column that matches the value in individual cells of the competitor code column.
To make it work with multiple lookup range, we're going to create arrays of boolean values (TRUE/FALSE, aka logical values) by comparing values from individual cells in competitor code column with values in individual competitorn columns. Now, we convert these boolean values into numerical values by performing a mathematical operation that does not alter its implied value (i.e. TRUE=1, FALSE=0). We're going to add these values directly to make it simple. The resulting array have four index with two possible values: 1 or 0. Since each item in MATCH's lookup_array is unique, then there can be only one TRUE or 1. The rest are FALSE or 0's. So, with that knowledge, we're going to use it as our lookup_value.
Let's dissect the formula:
=INDEX(B2:B5,MATCH(1,(K2=C2:C5)+(K2=D2:D5)+(K2=E2:E5)+(K2=F2:F5)+(K2=G2:G5),0))
My code 2 = INDEX({"My code 1";"My code 2";"My code 3";"My code 4"},MATCH)
My code 2 = INDEX({"My code 1";"My code 2";"My code 3";"My code 4"},(2))
2 = MATCH(1,(K2=C2:C5)+(K2=D2:D5)+(K2=E2:E5)+(K2=F2:F5)+(K2=G2:G5),0)
2 =MATCH(1,
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;TRUE;FALSE;FALSE},0))
OR
=MATCH(1,
{0;0;0;0}+
{0;0;0;0}+
{0;0;0;0}+
{0;0;0;0}+
{0;1;0;0},0))
=========
{0;1;0;0},0))
2 = MATCH(1,{0;1;0;0},0))
I hope this answer is helpful.
References and links:
INDEX function
MATCH function
Create an array formula
I need help writing a function to find "Th+4" and ignore all other attached chemical elements.
Example of the data;
/HASr+(aq) 1.2595E-12
Sr+2 2.9449E-06
SrCl+ 1.4637E-10
SrCO3 (aq) 1.01E-10
SrF+ 2.1778E-11
SrHCO3+ 3.2969E-09
How can I find only Sr+2 and ignore all the others? For now, I was using this function to find it, but it displays all elements containing Sr2+.
=IF(ISERROR(FIND("Sr+2",A7,1)),B7,"")
Please help,
Thank you !
Your question is very vague, but I assume that when you "locate" your value, you want to return the value to the right.
You can use Index() and Match() to do this for you.
Assuming that your lookup range is column A, and the value to return is column B, this should work:
=INDEX(A:B,MATCH("Sr+2", A:A),2)
Breaking Down the Formula
Index()
- A:B is the entire range to index. Your lookup value is column A, and your return value is column B
- Match() is returning the row number, which we will show that below.
- 2 is column to cross reference the return value of the row from Match(). Since Match() gives us the row #, this gives us the column number to "pin-point" the return value
Match()
- "Sr+2" is the string to be searched for
- A:A is the location to search for this string.
This returns the row to your Index() function
An alternate method from using Index() & Match() is to use VLOOKUP(). This function essentially combines the two previous functions for the same purpose in your case.
=VLOOKUP("Sr+2",A:B,2)
Using the VLOOKUP() Function
Use VLOOKUP, one of the lookup and reference functions, when you need to find things in a table or a range by row. For example, look up a price of an automotive part by the part number.
In its simplest form, the VLOOKUP function says:
=VLOOKUP(Value you want to look up, range where you want to lookup the value, the column number in the range containing the return value, Exact Match or Approximate Match – indicated as 0/FALSE or 1/TRUE).
I also found that this works for my problem;
=IF((EXACT($AG$38,A7)),B7,"")
Thank you for all your answers :)!
Have a great day!
I'm trying to do what should be a simple enough task: find the index of the last cell in an array that matches a certain value.
I am using a MATCH-INDEX function combination that is giving me incorrect, inconsistent results. I can't figure out the problem.
In this example I'm using an array with values of 1 or -1 and trying to find the index of the last 1 in the array.
My understanding is (and using the Evaluate Formula tool confirms), INDEX(A1:F1=1,0) should return an array of
{FALSE,TRUE,FALSE,TRUE,FALSE,FALSE}
Why does the MATCH(TRUE,...) not give a result of 4 when it is fed this index array? MATCH works backwards in the array and should return the index of the last match, which is the TRUE value in the 4th position.
But here this code is giving a result of 6.
To make matters worse, if I use the same code but change around the array fed into INDEX, the results are inconsistent. When I'm changing array values to 1 or -1, sometimes the formula result changes and sometimes it doesn't, and I can't figure out why.
Below, changing only the 3rd array value changes the result of the formula from 4 to 6. WHAT IS GOING ON?!
It seems that match only finds first, but not last.
But I have a possible solution, I would do it the following way:
expect: your values are between H4 AND H27, the value you look for is "39"
1: find the rownum for all matching cells
I4 --> I27: IF(H4 = 39; ROW(H4); -1)
2: find the max rownum in I4 --> I27
MAX(....)
3: subtract the rownum of first cell (zero- based index)
MAX(....) - ROW(H4)
4: to get it in only one cell put into a Matrix function (CONTROL SHIFT ENTER makes CURLY BRACKETS)
{=MAX(IF($H$4:$H$27=39;ROW(H4:H27);-1))-ROW(H4)}
sounds strange, but works :)
Index doesn't return an Array, but a number, as the name tells you, the "INDEX" of the element, which fulfills your question. With the last Parameter you can decide, whether it has to be exact or could be the next smaller or next bigger value (last both options will only work with sorted Input)
You can solve your question either in more then one step as written in my last answer or with matrix functions, in your special case (now with columns instead of rows):
{=MAX(IF(A1:F1=1;COL(A1:F1);-1))}