Curious Minds

Clear answers to science and history questions

VLOOKUP with Duplicates: How It Works

· 5 min read · Science

When VLOOKUP encounters duplicate values in its lookup column, it returns the first match it finds, searching from top to bottom. Any subsequent duplicates are ignored. This behavior is consistent across Excel and Google Sheets, and it is the single most important fact to understand when working with duplicated lookup keys.

The Basic Mechanics of VLOOKUP

VLOOKUP (vertical lookup) searches for a value in the leftmost column of a table and returns a value from a specified column in the same row. Its syntax is VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]). The fourth argument, range_lookup, is optional: TRUE (or omitted) performs an approximate match, while FALSE (or 0) performs an exact match. Most duplicate-related issues arise with exact match, because approximate match assumes the first column is sorted and uses a binary search that can behave unpredictably with unsorted or duplicated data.

With exact match, VLOOKUP scans the lookup column from the first row downward. As soon as it finds a cell equal to the lookup value, it stops and returns the corresponding value from the requested column. It does not check whether other rows contain the same value. This is by design, not a bug.

Why VLOOKUP Returns Only the First Match

The function is built for speed and simplicity. Scanning an entire column to collect all matches would require array handling and a different return structure. Instead, VLOOKUP returns a single scalar value. Microsoft's documentation explicitly states that if multiple values match the lookup value, the first one found is used. This makes VLOOKUP unsuitable for retrieving all instances of a duplicated key, but perfectly fine when you know the first occurrence is the one you want—for example, when duplicates represent historical records and the topmost row is the most recent.

In practice, this means the order of rows matters. If you sort the table differently, VLOOKUP may return a different result for the same lookup value. That is a common source of confusion when a workbook is re-sorted and formulas appear to change their answers.

How to Control Which Duplicate Is Returned

If you need a specific duplicate—say the last one, or the one with the highest date—you can manipulate the data before the lookup. Here are practical approaches:

  • Sort the table so the desired duplicate appears first. For example, sort by date descending to get the most recent record at the top.
  • Use a helper column that combines the lookup value with a unique identifier (like a row number or timestamp) and look up that combined key instead.
  • Use INDEX and MATCH with a condition (array formula) to find the last match, though this is more advanced and not covered by basic VLOOKUP.
  • Remove duplicates beforehand using Excel's Remove Duplicates feature if only one record per key is needed.

Each method has trade-offs. Sorting is simplest but changes the original order. Helper columns add complexity but preserve data integrity. Removing duplicates is destructive unless you keep a backup.

Common Problems and Misconceptions

One frequent misconception is that VLOOKUP will somehow sum or combine duplicate values. It will not. If you need to aggregate duplicates, use SUMIF, COUNTIF, or a pivot table. Another issue: if the lookup column contains duplicates and you use approximate match (TRUE), the function may return a value from a row that is not an exact match, especially if the column is not sorted ascending. This can produce seemingly random results. Always use exact match (FALSE) when duplicates exist and you need a precise match.

Also, VLOOKUP is case-insensitive. "Apple" and "apple" are treated as duplicates. If case matters, you need a different approach, such as using EXACT in an array formula.

Finally, duplicates can cause performance issues in very large datasets because VLOOKUP stops at the first match—which is actually faster—but if the first match is far down, it still scans many rows. The real performance hit comes from using whole-column references; limit the table_array to the actual data range.

VLOOKUP vs. Other Lookup Functions with Duplicates

INDEX/MATCH behaves identically to VLOOKUP with duplicates: it returns the first match. XLOOKUP, available in newer Excel versions, also returns the first match by default but offers a search_mode argument that can search from last to first, effectively returning the last duplicate. This is a significant advantage. In Google Sheets, VLOOKUP also returns the first match, but you can use FILTER or QUERY to return all matches.

For retrieving all duplicates, you need array formulas or dynamic arrays. In Excel 365, the FILTER function can return multiple rows: =FILTER(return_range, lookup_range=lookup_value). This spills results into adjacent cells. Older Excel versions require complex array formulas with SMALL and IF.

Practical Example: Duplicates in a Sales Table

Suppose you have a table of sales records with columns: Salesperson, Region, Amount. The Salesperson column contains duplicates because each person made multiple sales. If you use =VLOOKUP("Smith", A2:C10, 3, FALSE), you will get the Amount from the first row where "Smith" appears. If Smith appears in rows 2, 5, and 8, you get the amount from row 2 only. To get the total for Smith, use =SUMIF(A2:A10, "Smith", C2:C10). To get the last sale, you could sort by date descending and then VLOOKUP, or use XLOOKUP with search_mode -1.

This example highlights that VLOOKUP is a retrieval tool, not an aggregation tool. Knowing the difference prevents many errors.

Frequently Asked Questions

Does VLOOKUP return the first or last duplicate?

VLOOKUP returns the first duplicate it encounters when searching from top to bottom. It does not return the last duplicate unless you reverse the row order or use a different function like XLOOKUP with a reverse search.

Can VLOOKUP return multiple matches?

No, VLOOKUP returns only a single value. To return multiple matches, you need functions like FILTER (Excel 365) or array formulas that output to multiple cells.

What happens if there are duplicates and I use approximate match?

Approximate match (range_lookup TRUE) assumes the first column is sorted ascending. With duplicates, it may return a value from a row that is not an exact match, leading to incorrect results. Use exact match (FALSE) for reliable behavior with duplicates.

How can I make VLOOKUP return the last duplicate?

You can sort the table so the desired duplicate is first, or use XLOOKUP with search_mode -1 (search last to first). Alternatively, use an INDEX/MATCH array formula that looks up the last occurrence.

Is VLOOKUP case-sensitive with duplicates?

No, VLOOKUP is case-insensitive. "Apple" and "apple" are considered the same. If case sensitivity is required, use EXACT in an array formula or a helper column that converts case.

Why does VLOOKUP sometimes return a different duplicate after sorting?

Because VLOOKUP returns the first match, changing the row order changes which duplicate is first. Sorting the table alters the order, so the returned value can change.

In this article
  1. The Basic Mechanics of VLOOKUP
  2. Why VLOOKUP Returns Only the First Match
  3. How to Control Which Duplicate Is Returned
  4. Common Problems and Misconceptions
  5. VLOOKUP vs. Other Lookup Functions with Duplicates
  6. Practical Example: Duplicates in a Sales Table
  7. Frequently Asked Questions