
Zhrnutie
VLOOKUP je funkcia programu Excel na vyhľadanie údajov v tabuľke usporiadanej zvisle. VLOOKUP podporuje približné a presné zhody a zástupné znaky (*?) Pre čiastočné zhody. Hodnoty vyhľadávania musia byť uvedené v prvom stĺpci tabuľky odovzdanej do funkcie VLOOKUP.
Účel
Vyhľadajte hodnotu v tabuľke podľa zhody v prvom stĺpciNávratová hodnota
Zodpovedajúca hodnota z tabuľky.Syntax
= VLOOKUP (hodnota, tabuľka, col_index, (range_lookup))Argumenty
- hodnota - hodnota, ktorá sa má vyhľadať v prvom stĺpci tabuľky.
- tabuľka - Tabuľka, z ktorej sa má načítať hodnota.
- col_index - stĺpec v tabuľke, z ktorého sa má načítať hodnota.
- range_lookup - (voliteľné) TRUE = približná zhoda (predvolené). FALSE = presná zhoda.
Verzia
Excel 2003Poznámky k použitiu
VLOOKUP je funkcia programu Excel na získanie údajov z tabuľky usporiadanej zvisle. Hodnoty vyhľadávania musia byť uvedené v prvom stĺpci tabuľky odovzdanej do funkcie VLOOKUP. VLOOKUP podporuje približné a presné priraďovanie a zástupné znaky (*?) Pre čiastočné zhody.
Vertikálne údaje Čísla stĺpcov Iba vyzerá dobre | Zhodné režimy Presná zhoda | Približná zhoda | Prvý zápas | Zástupný znak | Obojsmerné vyhľadávanie | Viaceré kritériá # N / A chyby | Videá
V je pre zvislé
Účelom VÝHĽADU je získať informácie z takto usporiadanej tabuľky:
Pomocou čísla objednávky v stĺpci B ako vyhľadávacej hodnoty môže VLOOKUP získať pre každú objednávku ID zákazníka, čiastku, meno a štát. Napríklad pre získanie názvu zákazníka pre objednávku 1004 je vzorec:
=VLOOKUP(1004,B5:F9,4,FALSE) // returns "Sue Martin"
Pre horizontálne údaje môžete použiť HLOOKUP, INDEX a MATCH alebo XLOOKUP.
VLOOKUP je založený na číslach stĺpcov
Keď používate VLOOKUP, predstavte si, že každý stĺpec v tabuľke je očíslovaný, začínajúc zľava. Ak chcete získať hodnotu z konkrétneho stĺpca, zadajte príslušné číslo ako „index stĺpca“. Napríklad index stĺpca na získanie krstného mena uvedeného nižšie je 2:
Priezvisko a e-mail je možné získať v stĺpcoch 3 a 4:
=VLOOKUP(H3,B4:E13,2,FALSE) // first name =VLOOKUP(H3,B4:E13,3,FALSE) // last name =VLOOKUP(H3,B4:E13,4,FALSE) // email address
VLOOKUP vyzerá iba dobre
VLOOKUP môže pozerať iba doprava. Údaje, ktoré chcete načítať (výsledné hodnoty), sa môžu zobraziť v ľubovoľnom stĺpci napravo od vyhľadávacích hodnôt:
Ak potrebujete vyhľadať hodnoty vľavo, pozrite si INDEX a ZHODU alebo XLOOKUP.
Presná a približná zhoda
VLOOKUP má dva režimy zhody, presný a približný. Názov argumentu, ktorý riadi zhodu, je „ range_lookup “. Toto je mätúce meno, pretože sa zdá, že má niečo spoločné s rozsahmi buniek ako A1: A10. Slovo „rozsah“ v tomto prípade v skutočnosti označuje „rozsah hodnôt“ - keď je parameter range_lookup TRUE, funkcia VLOOKUP bude zodpovedať rozsahu hodnôt a nie presnej hodnote. Dobrým príkladom toho je použitie VLOOKUPU na výpočet známok.
Je dôležité si uvedomiť, že range_lookup je predvolene nastavený na TRUE, čo znamená, že VLOOKUP bude predvolene používať približnú zhodu, čo môže byť nebezpečné. Nastaviť range_lookup na FALSE pre vynútenie presnej zhody:
=VLOOKUP(value, table, col_index) // approximate match (default) =VLOOKUP(value, table, col_index, TRUE) // approximate match =VLOOKUP(value, table, col_index, FALSE) // exact match
Poznámka: Môžete tiež zadať nulu (0) namiesto FALSE pre presnú zhodu.
Presná zhoda
Vo väčšine prípadov budete pravdepodobne chcieť použiť VLOOKUP v režime presnej zhody. To dáva zmysel, keď máte jedinečný kľúč, ktorý môžete použiť ako vyhľadávaciu hodnotu, napríklad názov filmu v týchto údajoch:
Vzorec v H6 na nájdenie roku , založený na presnej zhode názvu filmu, je:
=VLOOKUP(H4,B5:E9,2,FALSE) // FALSE = exact match
Približná zhoda
In cases when you want the best match , not necessarily an exact match , you'll want to use approximate mode. For example, below we want to look up a commission rate in the table G5:H10. The lookup values come from column C. In this example, we need to use VLOOKUP in approximate match mode, because in most cases an exact match will never be found. The VLOOKUP formula in D5 is configured to perform an approximate match by setting the last argument to TRUE:
=VLOOKUP(C5,$G$5:$H$10,2,TRUE) // TRUE = approximate match
VLOOKUP will scan values in column G for the lookup value. If an exact match is found, VLOOKUP will use it. If not, VLOOKUP will "step back" and match the previous row.
Note: data must be sorted in ascending order by lookup value when you use approximate match mode with VLOOKUP.
First match
In the case of duplicate values, VLOOKUP will find the first match when the match mode is exact. In screen below, VLOOKUP is configured to find the price for the color "Green". There are three entries with the color Green, and VLOOKUP returns the price for the first entry, $17. The formula in cell F5 is:
=VLOOKUP(E5,B5:C11,2,FALSE) // returns 17
Wildcard match
The VLOOKUP function supports wildcards, which makes it possible to perform a partial match on a lookup value. For instance, you can use VLOOKUP to retrieve values from a table after typing in only part of a lookup value. To use wildcards with VLOOKUP, you must specify exact match mode by providing FALSE or 0 for the last argument, range_lookup . The formula in H7 retrieves the first name, "Michael", after typing "Aya" into cell H4:
=VLOOKUP($H$4&"*",$B$5:$E$104,2,FALSE)
Read a more detailed explanation here.
Two-way lookup
Inside the VLOOKUP function, the column index argument is normally hard-coded as a static number. However, you can also create a dynamic column index by using the MATCH function to locate the right column. This technique allows you to create a dynamic two-way lookup, matching on both rows and columns. In the screen below, VLOOKUP is configured to perform a lookup based on Name and Month. The formula in H6 is:
=VLOOKUP(H4,B5:E13,MATCH(H5,B4:E4,0),0)
For more details, see this example.
Note: In general, INDEX and MATCH is a more flexible way to perform two-way lookups.
Multiple criteria
The VLOOKUP function does not handle multiple criteria natively. However, you can use a helper column to join multiple fields together, and use these fields like multiple criteria inside VLOOKUP. In the example below, Column B is a helper column that concatenates first and last names together with this formula:
=C5&D5 // helper column
VLOOKUP is configured to do the the same thing to create a lookup value. The formula in H6 is:
=VLOOKUP(H4&H5,B5:E13,4,0)
For details, see this example.
Note: INDEX and MATCH and XLOOKUP are more robust ways to handle lookups based on multiple criteria.
VLOOKUP and #N/A errors
If you use VLOOKUP you will inevitably run into the #N/A error. The #N/A error just means "not found". For example, in the screen below, the lookup value "Toy Story 2" does not exist in the lookup table, and all three VLOOKUP formulas return #N/A:
One way to "trap" the NA error is to use the IFNA function like this:
The formula in H6 is:
=IFNA(VLOOKUP(H4,B5:E9,2,FALSE),"Not found")
The message can be customized as desired. To return nothing (i.e. to display a blank result) when VLOOKUP returns #N/A you can use an empty string like this:
=IFNA(VLOOKUP(H4,B5:E9,2,FALSE),"") // no message
The #N/A error is useful because it tells you something is wrong. In practice, there are many reasons why you might see this error, including:
- The lookup value does not exist in the table
- The lookup value is misspelled, or contains extra space
- Match mode is exact, but should be approximate
- The table range is not entered correctly
- You are copying VLOOKUP, and the table reference is not locked
Read more: VLOOKUP without #N/A errors
More about VLOOKUP
- More VLOOKUP examples
- VLOOKUP videos
- 23 tips for using VLOOKUP
Other notes
- Range_lookup controls whether value needs to match exactly or not. The default is TRUE = allow non-exact match.
- Set range_lookup to FALSE to require an exact match and TRUE to allow a non-exact match .
- If range_lookup is TRUE (the default setting), a non-exact match will cause the VLOOKUP function to match the nearest value in the table that is still less than value .
- When range_lookup is omitted, the VLOOKUP function will allow a non-exact match, but it will use an exact match if one exists.
- If range_lookup is TRUE (the default setting) make sure that lookup values in the first row of the table are sorted in ascending order. Otherwise, VLOOKUP may return an incorrect or unexpected value.
- If range_lookup is FALSE (require exact match), values in the first column of table do not need to be sorted.
Related videos





