MATCH function
Tip: Try using the new XMATCH function, an improved version of MATCH that works in any direction and returns exact matches by default, making it easier and more convenient to use than its predecessor.
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. For example, if the range A1:A3 contains the values 5, 25, and 38, then the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.
Tip: Use MATCH instead of one of the LOOKUP functions when you need the position of an item in a range instead of the item itself. For example, you might use the MATCH function to provide a value for the row_num argument of the INDEX function.
Syntax
MATCH(lookup_value, lookup_array, [match_type])
The MATCH function syntax has the following arguments:
-
lookup_value Required. The value that you want to match in lookup_array. For example, when you look up someone’s number in a telephone book, you are using the person’s name as the lookup value, but the telephone number is the value you want.
The lookup_value argument can be a value (number, text, or logical value) or a cell reference to a number, text, or logical value.
-
lookup_array Required. The range of cells being searched.
-
match_type Optional. The number -1, 0, or 1. The match_type argument specifies how Excel matches lookup_value with values in lookup_array. The default value for this argument is 1.
The following table describes how the function finds values based on the setting of the match_type argument.
Match_type |
Behavior |
1 or omitted |
MATCH finds the largest value that is less than or equal to lookup_value. The values in the lookup_array argument must be placed in ascending order, for example: …-2, -1, 0, 1, 2, …, A-Z, FALSE, TRUE. |
0 |
MATCH finds the first value that is exactly equal to lookup_value. The values in the lookup_array argument can be in any order. |
-1 |
MATCH finds the smallest value that is greater than or equal tolookup_value. The values in the lookup_array argument must be placed in descending order, for example: TRUE, FALSE, Z-A, …2, 1, 0, -1, -2, …, and so on. |
-
MATCH returns the position of the matched value within lookup_array, not the value itself. For example, MATCH(«b»,{«a»,»b»,»c«},0) returns 2, which is the relative position of «b» within the array {«a»,»b»,»c»}.
-
MATCH does not distinguish between uppercase and lowercase letters when matching text values.
-
If MATCH is unsuccessful in finding a match, it returns the #N/A error value.
-
If match_type is 0 and lookup_value is a text string, you can use the wildcard characters — the question mark (?) and asterisk (*) — in the lookup_value argument. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.
Product |
Count |
|
Bananas |
25 |
|
Oranges |
38 |
|
Apples |
40 |
|
Pears |
41 |
|
Formula |
Description |
Result |
=MATCH(39,B2:B5,1) |
Because there is not an exact match, the position of the next lowest value (38) in the range B2:B5 is returned. |
2 |
=MATCH(41,B2:B5,0) |
The position of the value 41 in the range B2:B5. |
4 |
=MATCH(40,B2:B5,-1) |
Returns an error because the values in the range B2:B5 are not in descending order. |
#N/A |
Need more help?
The MATCH function is used to determine the position of a value in a range or array. For example, in the screenshot above, the formula in cell E6 is configured to get the position of the value in cell D6. The MATCH function returns 5 because the lookup value («peach») is in the 5th position in the range B6:B14:
=MATCH(D6,B6:B14,0) // returns 5
The MATCH function can perform exact and approximate matches and supports wildcards (* ?) for partial matches. There are 3 separate match modes (set by the match_type argument), as described below.
Note: the MATCH function will always return the first match. If you need to return the last match (reverse search) see the XMATCH function. If you want to return all matches, see the FILTER function.
MATCH only supports one-dimensional arrays or ranges, either vertical or horizontal. However, you can use MATCH to locate values in a two-dimensional range or table by giving MATCH the single column (or row) that contains the lookup value. You can even use MATCH twice in a single formula to find a matching row and column at the same time.
Frequently, the MATCH function is combined with the INDEX function to retrieve a value at a certain (matched) position. In other words, MATCH figures out the position, and INDEX returns the value at that position. For a detailed overview with simple examples, see How to use INDEX and MATCH.
Match type information
Match type is optional. If not provided, match_type defaults to 1 (exact or next smallest). When match_type is 1 or -1, it is sometimes referred to as an «approximate match». However, keep in mind that MATCH will always perform an exact match when possible, as noted in the table below:
Match type | Behavior | Details |
---|---|---|
1 | Approximate | MATCH finds the largest value less than or equal to the lookup value. The lookup array must be sorted in ascending order. |
0 | Exact | MATCH finds the first value equal to the lookup value. The lookup array does not need to be sorted. |
-1 | Approximate | MATCH finds the smallest value greater than or equal to the lookup value. The lookup array must be sorted in descending order. |
(omitted) | Approximate | When match_type is omitted, it defaults to 1 with behavior as explained above. |
Caution: Be sure to set match_type to zero (0) if you need an exact match. The default setting of 1 can cause MATCH to return results that look normal but are in fact incorrect. Explicitly providing a value for match_type, is a good reminder of what behavior is expected.
Exact match
When match_type is zero (0), MATCH performs an exact match only. In the example below, the formula in E3 is:
=MATCH(E2,B3:B11,0) // returns 4
In the formula above, the lookup value comes from cell E2. If the lookup value is hardcoded into the formula, it must be enclosed in double quotes («»), since it is a text value:
=MATCH("Mars",B3:B11,0)
Note: MATCH is not case-sensitive, so «Mars» and «mars» will both return 4.
Approximate match
When match_type is set to 1, MATCH will perform an approximate match on values sorted A-Z, finding the largest value less than or equal to the lookup value. In the example shown below, the formula in E3 is:
=MATCH(E2,B3:B11,1) // returns 5
Wildcard match
When match_type is set to zero (0), MATCH can use wildcards. In the example shown below, the formula in E3 is:
=MATCH(E2,B3:B11,0) // returns 6
This is equivalent to:
=MATCH("pq*",B3:B11,0)
INDEX and MATCH
The MATCH function is commonly used together with the INDEX function. The resulting formula is called «INDEX and MATCH». For example, in the screen below, INDEX and MATCH are used to return the cost of a code entered in cell F4. The formula in F5 is:
=INDEX(C5:C12,MATCH(F4,B5:B12,0)) // returns 150
In this example, MATCH is set up to perform an exact match. The MATCH function locates the code ABX-075 and returns its position (7) directly to the INDEX function as the row number. The INDEX function then returns the 7th value from the range C5:C12 as a final result. The formula is solved like this:
=INDEX(C5:C12,MATCH(F4,B5:B12,0))
=INDEX(C5:C12,7)
=150
See below for more examples of the MATCH function. For an overview of how to use INDEX and MATCH with many examples, see: How to use INDEX and MATCH.
Case-sensitive match
The MATCH function is not case-sensitive. However, MATCH can be configured to perform a case-sensitive match when combined with the EXACT function in a generic formula like this:
=MATCH(TRUE,EXACT(lookup_value,array),0))
The EXACT function compares every value in array with the lookup_value in a case-sensitive manner. This formula is explained with an INDEX and MATCH example here.
Notes
- MATCH is not case-sensitive.
- MATCH returns the #N/A error if no match is found.
- MATCH only works with text up to 255 characters in length.
- In case of duplicates, MATCH returns the first match.
- If match_type is -1 or 1, the lookup_array must be sorted as noted above.
- If match_type is 0, the lookup_value can contain the wildcards.
- The MATCH function is frequently used together with the INDEX function.
Okay, I have been trying to find a solution for this and I just don’t seem to be able. I can’t even break down the problem properly. This is the idea.
I have two sheets with many rows (one with 800 and the other with 300,000). Each row contains a Name column and then several columns that contain information about this Name. Each sheet has different kinds of information.
I want to consolidate these two sheets into a master sheet based on this Name column they both have, so the consolidate function is perfect for this. Now the problem is that the names don’t match perfectly.
For example Sheet1 contains
«Company B.V.», «Info #1»
«Company Total», «Info #2»
«Company Ltd», «Info #3»
and sheet 2 contains
«Company and Co.», «Info #4»
«Company and Co», «Info #5»
Sheet 1 contains all the names that are going to be used (around a 100 but in different forms as stated above) and sheet 2 contains all these 100 in multiple rows plus names that aren’t in the 100 list and therefore I don’t care about.
How would I make a VBA code project where the end result would be something like this, Master sheet:
«Company», «Info #1», «Info #2», «Info #3», «Info #4», «Info #5»
for every single «Company» (the 100 list) in there??
I do hope there is a solution for this. I’m pretty new to VBA projects, but I have done some minimal coding before.
How to Use the MATCH function in Excel: Step-by-Step
The MATCH function belongs to the list of Excel’s reference/lookup functions. It looks for a value in a lookup array like all the lookup functions do 👀
However, once found, it doesn’t return the corresponding value. But the relative position of the lookup value in the lookup array.
And that’s not it – the MATCH function can do just so much in Excel. So let’s jump into the guide below to learn it all.
Here’s our free sample workbook for this guide for you to download and tag along with the guide ⛵
How to use the MATCH function
The MATCH function of Excel looks for a given value in an array and returns its relative position from that array 🏆
The function is a really simple one, and you’ll enjoy it as we start exploring it. So let’s dive straight into an example.
Here we have a list of students with their scores in English.
It’s hard to find a student from this list readily. And the larger the list grows, the harder it gets 🥴
Do we have a function that can help us find the position of any student from this list readily Let’s try the MATCH function here to find the position of Addams.
- Begin writing the MATCH function as follows.
= MATCH (
- Write in the lookup_value as the first argument of the MATCH function.
= MATCH (B7
We are looking for the position of Addams – so that makes our lookup value. In this case, our lookup value rests in Cell B7, so we are creating a reference to it.
- Refer to the lookup_range as the second argument.
= MATCH (B7, A2:A5
Where should the MATCH function look for the value “Addams”?
This is the table that contains the student names (Cell A2 to Cell A5).
Do not include the headers in this range. If the headers are included in the lookup range, the relative position of the lookup value would be pushed one position down the list.
- Define the match_type as 0.
= MATCH (B7, A2:A5, 0)
Pro Tip!
The MATCH function has three different match types 3️⃣
0 – Search for the exact match of the lookup_value.
1 (or omitted) – Search for the largest value less than or equal to the lookup value. The lookup array must be arranged in ascending order for this to work.
-1 – Search for the smallest value greater than or equal to the lookup value. The lookup array must be arranged in descending order for this to work.
The match_type is an optional argument. If omitted, Excel sets it to 1 by default.
For now, we are setting the match_type to 0 as we want Excel to lookup for an exact match. The name Addams is present in the list with the same spelling so the MATCH function can perform an exact match.
- Press Enter as we’re done writing the function now 👍
And there you go! Excel finds the relative position of Addams from the list of Students.
Addams is in the second position on the list. As the scores next to Addams are arranged in ascending order, this also tells that Addams scored the second least marks among all 🥈
The MATCH function is not a case-sensitive function. It doesn’t differentiate between uppercase and lowercase letters.
Approximate match types
There are three different match types to the MATCH function, and we have only seen one of them yet (the exact match_type).
It’s time that we now look into how the MATCH function works under the other two match types. Let’s take the same example as above – but this time, a little twisted.
For a quick revision, here is the scorecard of the students 📝
Match type (1)
Let’s find which student scored 90 or the next highest mark less than 90.
Must note that for the MATCH function to work with match type 1, the lookup array must be sorted in ascending order.
And take a quick look at our lookup array – it starts from 65 and goes up to 89. Hence, it is already arranged in ascending order.
- Write the lookup value of the MATCH function as follows:
= MATCH (B7
We want to find students who scored 90 (or nearest to 90 marks). So that makes up our lookup value.
- Write in the lookup array as the next argument.
= MATCH (B7, B2:B5
The score is to be looked up from the column of scores. And so this time our lookup array is B2 to B5 🚀
- Set the match type to 1.
= MATCH (B7, B2:B5, 1)
Pro Tip!
Why have we set the match type to 1? That’s because we want to find the student who scored 90 marks. Or if there’s no such student, then we want to find the one who scored the highest marks less than 90.
Under match type 1, the MATCH function search for the largest value less than or equal to the lookup value i.e. 90 🔍
- And hit “Enter”.
The MATCH function returns 4. Why is that?
Because we have Cheryl with 89 marks at position 4. None of the students scored 90 marks. And the second highest after 90 is 89 marks 🤩
Match type (-1)
To test match type (-1), let’s find which student scored 80 or the least marks greater than 80.
Must note that for the MATCH function to work with match type -1, the lookup array must be sorted in descending order.
- Sort your lookup array in descending order by clicking on the header (Scores here).
- Go to Home Tab > Sort and Filter.
- Choose Sort Z to A “Highest to Lowest”
- And you have your list sorted in descending order.
Now, to find the student who scored 80 Marks or the next highest marks:
- Write the MATCH function with the following changes from above.
= MATCH (B7, B2:B5, -1)
Our lookup value is now 80. And we have set the match type to -1.
- Hit Enter and there comes the results.
The MATCH function returns 2. Why is that?
Because at position 2, we have Ana with 82 marks. After 80, we have 82 on the list (the next highest to our lookup value of 80). That’s match type -1 returns 🎯
Other MATCH formula examples
We yet have more Excel MATCH function examples. Let’s look into them here.
In the image below, we have a list of items with different codes to them 📍
From this list, we want to find the position of the Item “CAR”. But we don’t exactly know the code that suffixes it. How can then we find it?
Under the match type (0), the MATCH function can be used with wildcard characters.
So even if we do not know the exact code after the item name “cars”, we can use a wildcard character. Let’s do it here then:
- Write the MATCH function as follows:
= MATCH (
- Write the lookup value (Car) as the first argument of the MATCH function.
= MATCH (“Car*”,
As we don’t know the exact code that comes at the end of the item name, we have used an asterisk at the end 😎
An asterisk represents any number of characters at the end of the item name.
- Specify the lookup array as the next argument.
= MATCH (“Car*”, A2:A7,
- Set the match type to 0.
= MATCH (“Car*”, A2:A7, 0)
- And hit “Enter” to get going.
See that? The MATCH function has found the position of Item CAR-34 from the list. Although we never specified the complete name of the item 💪
Pro Tip!
Must note that there were two items by the name CAR in the list. However, the MATCH function returned to position 2 only 🤔
This is because if there are multiple instances of the lookup value in the lookup array, the MATCH function returns the position of the first instance only.
That’s it – Now what
The guide above teaches us the ins and outs of the MATCH function of Excel. We began learning from a simple example of the MATCH function.
And until now we have seen multiple examples of how to use the MATCH function with different match modes.
The MATCH function is a very commonly used function of Excel. It is one of the easier yet very useful functions of Excel.
And that’s not it. There are many more similar useful functions of Excel that you must know about (even if you’re a beginner) 👦
Like the VLOOKUP, SUMIF, and IF functions of Excel. To learn them, enroll in my 30-minute free email course that will teach you these (and many more) functions of Excel.
Other resources
You’d often see the MATCH function is used together with the INDEX function. Both of these functions together to work like an advanced lookup function.
In addition to these, other lookup functions of Excel include the HLOOKUP, VLOOKUP, and XLOOKUP functions of Excel.
Frequently asked question
No. The MATCH function only returns the relative position of a lookup value in a lookup array and not the value itself.
To get the corresponding value for a look-up value, the MATCH function must be used together with the INDEX function.
However, the VLOOKUP function can do all of this alone.
The MATCH function is a lookup/reference function of Excel.
It looks up for a given value in a look-up array. And if found, it returns the relative position of the lookup value in the lookup array.
Kasper Langmann2023-01-11T20:00:46+00:00
Page load link
На чтение 2 мин
Функция ПОИСКПОЗ в Excel используют для поиска точной позиции искомого значения в списке или массиве данных.
Содержание
- Что возвращает функция
- Синтаксис
- Аргументы функции
- Дополнительная информация
- Примеры использования функции ПОИСКПОЗ в Excel
Что возвращает функция
Возвращает число, соответствующее позиции искомого значения.
Больше лайфхаков в нашем Telegram Подписаться
Синтаксис
=MATCH(lookup_value, lookup_array, [match_type]) — английская версия
=ПОИСКПОЗ(искомое_значение;просматриваемый_массив;[тип_сопоставления]) — русская версия
Аргументы функции
- lookup_value (искомое_значение) — значение, с которым вы хотите сопоставить данные из массива или списка данных;
- lookup_array (просматриваемый_массив) — диапазон ячеек в котором вы осуществляете поиск искомых данных;
- [match_type] ([тип_сопоставления]) — (не обязательно) — этот аргумент определяет каким образом, будет осуществлен поиск. Допустимые значения для аргумента: «-1», «0», «1» (подробней читайте ниже).
Дополнительная информация
- Чаще всего функция MATCH используется в сочетании с функцией INDEX (ИНДЕКС);
- Подстановочные знаки могут использоваться в аргументах функции в тех случаях, когда значение поиска — текстовая строка;
- При использовании функции ПОИСКПОЗ регистр букв не учитывается;
- Функция возвращает #N/A ошибку, если искомое значение не найдено;
- Аргумент match_type (тип_сопоставления) определяет каким образом, будет осуществлен поиск:
— Если аргумент match_type (тип_сопоставления) = 0, то это критерий точного соответствия. Он возвращает первую точную позицию соответствия (или ошибку, если совпадения нет);
— Если аргумент match_type (тип_сопоставления) = 1 (по умолчанию), то в таком случае данные должны быть отсортированы в порядке возрастания для этой опции. Функция возвращает наибольшее значение, равное или меньшее значения поиска.
— Если аргумент match_type (тип_сопоставления) = -1, то в таком случае данные должны быть отсортированы в порядке убывания для этой опции. Функция возвращает наименьшее и наибольшее значения поиска.
Примеры использования функции ПОИСКПОЗ в Excel