Sådan bruges Excel VLOOKUP-funktionen

Resumé

VLOOKUP er en Excel-funktion til at slå data op i en tabel, der er organiseret lodret. VLOOKUP understøtter omtrentlig og nøjagtig matchning og jokertegn (*?) Til delvise matches. Opslagsværdier skal vises i den første kolonne i tabellen, der sendes til VLOOKUP.

Formål

Slå en værdi op i en tabel ved at matche den første kolonne

Returneringsværdi

Den matchede værdi fra en tabel.

Syntaks

= VLOOKUP (værdi, tabel, col_index, (range_lookup))

Argumenter

  • værdi - Værdien, du skal kigge efter i den første kolonne i en tabel.
  • tabel - Den tabel, hvorfra en værdi kan hentes.
  • col_index - Kolonnen i tabellen, hvorfra en værdi kan hentes.
  • range_lookup - (valgfrit) TRUE = omtrentlig match (standard). FALSE = nøjagtigt match.

Version

Excel 2003

Brugsanvisninger

VLOOKUP er en Excel-funktion til at få data fra en tabel organiseret lodret. Opslagsværdier skal vises i den første kolonne i tabellen, der sendes til VLOOKUP. VLOOKUP understøtter omtrentlig og nøjagtig matchning og jokertegn (*?) For delvise matches.

Lodrette data Kolonnetal | Ser kun rigtigt ud | Matchende tilstande | Præcis match | Omtrentlig kamp | Første kamp | Wildcard-kamp | Tovejs opslag | Flere kriterier | # N / A-fejl | Videoer

V er for lodret

Formålet med VLOOKUP er at få oplysninger fra en tabel organiseret som denne:

Ved hjælp af ordrenummeret i kolonne B som en opslagsværdi kan VLOOKUP få kunde-id, beløb, navn og stat for enhver ordre. For at få kundenavn for ordre 1004 er formlen f.eks .:

=VLOOKUP(1004,B5:F9,4,FALSE) // returns "Sue Martin"

Til vandrette data kan du bruge HLOOKUP, INDEX og MATCH eller XLOOKUP.

VLOOKUP er baseret på kolonnetal

Når du bruger VLOOKUP, forestil dig at hver kolonne i tabellen er nummereret startende fra venstre. For at få en værdi fra en bestemt kolonne skal du angive det passende nummer som "kolonneindeks". For eksempel er kolonneindekset for at hente fornavnet nedenfor 2:

Efternavnet og e-mailen kan hentes med kolonne 3 og 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 ser kun rigtigt ud

VLOOKUP kan kun se til højre. De data, du vil hente (resultatværdier), kan vises i en hvilken som helst kolonne til højre for opslagsværdierne:

Hvis du har brug for at slå værdier til venstre op, se INDEX og MATCH eller XLOOKUP.

Præcis og omtrentlig matchning

VLOOKUP har to matchende tilstande, nøjagtige og omtrentlige. Navnet på argumentet, der styrer matchning, er " range_lookup ". Dette er et forvirrende navn, fordi det ser ud til at have noget at gøre med celleområder som A1: A10. Faktisk henviser ordet "rækkevidde" i dette tilfælde til "værdiområde" - når interval_opslag er SAND, vil VLOOKUP matche et interval af værdier snarere end en nøjagtig værdi. Et godt eksempel på dette er at bruge VLOOKUP til at beregne karakterer.

Det er vigtigt at forstå, at range_lookup som standard er SAND, hvilket betyder, at VLOOKUP som standard bruger omtrentlig matching, hvilket kan være farligt. Indstil range_lookup til FALSE for at tvinge nøjagtig matchning:

=VLOOKUP(value, table, col_index) // approximate match (default) =VLOOKUP(value, table, col_index, TRUE) // approximate match =VLOOKUP(value, table, col_index, FALSE) // exact match

Bemærk: Du kan også angive nul (0) i stedet for FALSK for et nøjagtigt match.

Præcis match

I de fleste tilfælde vil du sandsynligvis bruge VLOOKUP i nøjagtig matchningstilstand. Dette giver mening, når du har en unik nøgle til at bruge som en opslagsværdi, for eksempel filmtitlen i disse data:

Formlen i H6 for at finde År , baseret på et nøjagtigt match af filmtitel, er:

=VLOOKUP(H4,B5:E9,2,FALSE) // FALSE = exact match

Omtrentlig kamp

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

Sådan bruges VLOOKUP til omtrentlige matches I denne video ser vi på, hvordan vi konfigurerer VLOOKUP til at slå værdier op baseret på et omtrentligt match. Dette er godt for skattesatser, porto, provisioner og lignende. Sådan udskiftes indlejrede IF'er med VLOOKUP I denne korte video ser vi på, hvordan man udskifter en typisk indlejret IF-formel med en VLOOKUP-formel. Sammenlignet med indlejrede IF-udsagn er VLOOKUP enklere og mere gennemsigtig. Det er også lettere at justere senere. Sådan grupperes værdier med VLOOKUP I denne video ser vi på en enkel måde at bruge VLOOKUP til at gruppere data i specifikke kategorier. Sådan bruges VLOOKUP med en tabel I denne video ser vi på, hvordan du bruger VLOOKUP til at slå værdier op i en Excel-tabel. Sådan bruges INDEX og MATCH med en tabel I denne video ser vi på, hvordan man bruger INDEX og MATCH med en Excel-tabel. Brug af INDEX og MATCH med en Excel-tabel er vidunderligt ligetil. Strukturerede referencer inde i en tabel I denne video ser vi på, hvordan man bruger struktureret referencesyntaks inde i en tabel.

Interessante artikler...