Excel: Match returns error - excel

I have this list in excel:
ID (A) | Name (B)
1 | xyz
2 | Yzx s.r.o
3 | xxx a.s.
...
In another list, I have only names and need to assign IDs to them based on the list above.
I use this function =Match(H4; ListName!B2:B50; 0) (H4 cell contains name of company I want to match from other list and get ID for it).
When
there is no match, match function returns #Nedostupný (#Not available)
there is a match, match function returns #Názov? (#Name?)
EDIT: what could cause this problem? Does Match function works with strings that contains whitespaces, dots, or other special characters? Does a column type matter (whether format is set to text or not)... ?
PS: I wanted to get number of row where there is a match and then just select ID from A column of same row. Is there an easier way? How would I combine column Name with row returned from match? something like =A+Match(...)?

Like simoco said above, you might have problem with localized function name.
You should always use fixed references to lookup lists, like this: =Match(H4; ListName!$B$2:B$50$; 0) or this: =Match(H4; ListName!$B:$B; 0) otherwise when you fill the formula down the list reference will also move down: =Match(H4; ListName!B3:B51; 0), =Match(H4; ListName!B4:B52; 0) etc. so it will not contain the data you need.
To combine or rather concatenate strings, use & operator: ="A"&MATCH(...).
Probably you should consider using VLOOKUP() function instead of MATCH() it returns the value from another column based on the search in first column rather than the number position of value you're looking for.

Firstly, the syntax of your function is incorrect - the MATCH function uses a comma (,) as the separator between individual arguments, not semicolons (;).
Secondly, you should use absolute cell referencing for your lookup array in the MATCH function.
Thirdly, you need to ensure that the worksheet in which your lookup array is stored is called ListName (i.e. the same as that referenced in your formula); there shouldn't be any spaces in your worksheet name (e.g. List Name, etc), as this will prevent Excel from referencing the correct worksheet in your workbook [I'm assuming that you are calling the MATCH function from within the same workbook (though not necessarily the same worksheet) as your lookup array].
Hence, your MATCH function should read:
=Match(H4,ListName!$B$2:$B$50,0)
And I've checked this code - it works perfectly for your intended purpose (as described in your question above) when using either Excel 2010 or Excel 2013.

Related

MATCH subtracting afterwards? MATCH (lookup;array;match_type) -1

The question: if MATCH uses (lookup;array;match type) why there is a -1 after?
I have an Excel sheet at work that uses match in a way I cannot figure out.
The original formula:
=IF(E2<>"";OFFSET('Sheet1'!$A$2;MATCH(E2;Streams;0)-1;0;COUNTIF(Streams;E2);1);ITID)
The break down for the MATCH's part is:
MATCH(E2;Streams;0)-1;
The lookup value "E2" contains selectable values from "Streams", which is a named list. This named list "Streams" contains non numeric values like:
LOG
PLTP
PTP
OTC
etc...
Just understood that Match gives back the number position of the result, not the result itself.

How do I use INDIRECT inside an Excel array formula?

The situation
In the sheet "Planning" I have an area that contains pairs of sessions (strings) and hours (numbers) in adjacent cells (e.g. D11 and E11, I12 and J12 etc.) One session can occur multiple times.
D11:E11 is | Foo | 8 |
I12:J12 is | Foo | 4 |
In another sheet, I want to find a session in the Planning sheet and return an array with all the hours booked on that session (to calculate a total)
I use an array formula with a conditional and intend to use the SMALL function to retrieve the results from the array
The problem
The following formula returns all the correct references to hours booked on "Foo", so far so good.
=IF(Planning!$D$11:$CV$18="Foo";ADDRESS(ROW(Planning!$D$11:$CV$18);COLUMN(Planning!$D$11:$CV$18)+1;;;"Planning"))
{"Planning!$E$11"\FALSE\FALSE\FALSE\FALSE\"Planning!$J$12"}
However, if I use the INDIRECT function to retrieve the values of those references, they always return the value of the first reference in the array ("Planning!$E$11")
=IF(Planning!$D$11:$CV$18="Foo";INDIRECT(ADDRESS(ROW(Planning!$D$11:$CV$18);COLUMN(Planning!$D$11:$CV$18)+1;;;"Planning")))
{8\FALSE\FALSE\FALSE\FALSE\8}
How do I retrieve the correct values? Or should I tackle the problem in a whole different way?
Screenshots
The planning sheet
The overview I want
Since I was mainly interested in the total of planned hours, I eventually used the following formula:
=SUM(SUM(INDIRECT(IF(Planning!$D$11:$CV$18="Foo";(ADDRESS(ROW(Planning!$D$11:$CV$18);COLUMN(Planning!$D$11:$CV$18)+1;;;"Planning"));"$U$19"))))
IF: Create the array with references to the Planning sheet if the string is found. If it's not found, add the reference $U$19.
Using INDIRECT, replace all references with the values in the Planning sheet. $U$19 contains the value 0.
Then use SUM twice to sum up all the values. I don't know why, but see
Is it possible to have array as an argument to INDIRECT(), so INDIRECT() returns array?
https://superuser.com/questions/1196243/simplify-a-sum-of-indirect-cell-values
Indirect doest work in most array formulas. If you give it a string that refers to an array, like "A1:A10" it it returns those cells as expected but thats about it. You can use that array as the input to another function but you cant send an array output from another function to INDIRECT(). (Or at least i have not figured out a way)
Try using the INDEX function with the ROW function.
INDIRECT("A1:A10") is similar to
INDEX(A:A,ROW(A1:A10))
However the former is less flexible.
Comsider:
INDEX(A:A,FILTER(ROW(A1:A10),NOT(ISBLANK(A1:A10))*ISNUMBER(A1:A10)))
This returns an array containing the numerical values in the range but does not treat an empty cell as zero. Watch your order of operations and parenthesis.
The product NOT(ISBLANK(A1:A10)*ISNUMBER(A1:A10) is the inner product of two vectors of boolean values.
ROW(A1:A10) creates a vector of row values of the of the elements in that range. Then filter throws out any where the corespinsing element of the boolean vector is 0. Index then returns an array of values of the cells in its range coresponding to those rows. The range given to INDEX could be any row in fact. Not just the one your selecting on. Using the entire column (for example A:A) allows excel to automatically update the references if you move the source data, for instance if you insert a header row. If you use a specific range you will need to add an offset to the row value and it will not automatically update refernces. (Without a far more complex formula)

INDEX/MATCH with 4 columns

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

How to create a list out of a text string in another cell?

I need to know how i can use a string in a cell like: {"Alpha";"Beta";"Gamma";"Delta"}
in an index-function in another cell.
If i write =INDEX({"Alpha";"Beta";"Gamma";"Delta"};2) it correctly shows Beta in the cell.
If i fill the cell A1 with
{"Alpha";"Beta";"Gamma";"Delta"}
or
={"Alpha";"Beta";"Gamma";"Delta"}
and fill another cell with
=INDEX(A1;2)
or
=INDEX(INDIRECT(A1);2)
it throws a reference-error. Is this just a formatting issue or not possible in excel?
Assuming that the list is comma-separated, e.g. "Alpha,Beta,Gamma,Delta", this:
TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",LEN(A1))),LEN(A1)*(ROW(INDEX(A:A,1):INDEX(A:A,1+LEN(A1)-LEN(SUBSTITUTE(A1,",",""))))-1)+1,LEN(A1)))
will generate the array {"Alpha";"Beta";"Gamma";"Delta"} which can then be passed to some function for processing:
Hence you could use:
=INDEX(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",LEN(A1))),LEN(A1)*(ROW(INDEX(A:A,1):INDEX(A:A,1+LEN(A1)-LEN(SUBSTITUTE(A1,",",""))))-1)+1,LEN(A1))),n)
where n is some index of your choosing. For example, with n=2, the above would return "Beta" for the example string given.
However, given that you appear to wish to pass this array to a simple INDEX construction, it is probably preferable to use instead:
=MID(A1,FIND("ζ",SUBSTITUTE(","&A1&",",",","ζ",n)),MMULT(FIND("ζ",SUBSTITUTE(","&A1&",",",","ζ",n+{0,1})),{-1;1})-1)
where, again, the two instances of n should be replaced with your choice of index.
Regards

Get column by finding value in the row

In Excel, I've looked into hlookup, vlookup, match and index but none of these functions do following:
I need to find a text value in A1:Z1 and get the column of it. For example, I found the value in F1, then I want a result F:F.
EDIT: This is the function I want it to be added to:
=COUNTIFS(Source!B:B;Result!C3;Source!AT:AT;Result!$D$2)
I need the Source!B:B and alternatively Source!AT:AT be a search function that looks for a specific value in my table row and column in different sheet (Source).
INDEX function can return a whole column, e.g. assuming you want to search for "x" in A1:Z1 try
=INDEX(A:Z;0;MATCH("x";A1:Z1;0))
Note: this doesn't return a text string like F:F, it returns a reference to the column in question which you would normally use within a function that expects a whole column reference, e.g. SUM, SUMIF, LOOKUP etc.
Edited: You can use the above in COUNTIFS function like this:
=COUNTIFS(INDEX(Source!A:Z;0;MATCH("x";Source!A1:Z1;0));Result!C3;Source!AT:AT;Result!$D$2)
That makes the first range dynamic (between columns A and Z - extend as required) based on where "x" is first found in Source!A1:Z1, e.g. if "x" is first found in J1 then COUNTIFS uses Source!J:J for the first range - you can do that for any of the ranges in COUNTIFS
You can use this (it will return E:E, which you could then use INDIRECT with to return a workable range). This uses "words" as the word to match and stop at the first match:
=SUBSTITUTE(
ADDRESS(1,MATCH("words",$A$1:$Z$1,0),4),"1",
":"&
SUBSTITUTE(ADDRESS(1,MATCH("words",$A$1:$Z$1,0),4),"1",""))
This works by using MATCH to find the position of the occurrence in your range (in this case, 5), and then using ADDRESS, with row_num = 1 and column_num = the result of the match. Using 4 for the abs_num argument ensures that the returned value will be without the $'s. You then substitute out the 1 in E1 with ":" and concatenate it with the same formula, giving you E:E as a string. You can then do look-ups based on that range (using INDIRECT), such as this:

Resources