Skip to content

Match data

VLOOKUP Returns the First Match: How Duplicate Values Cause Wrong Results

VLOOKUP silently picks the first matching row when IDs repeat. Find duplicate keys and choose an explicit rule before bringing columns across.

TidyCell

Match & Merge

Bring selected fields across by a shared ID. Review missing and duplicate keys before keeping the result.

Open Match & Merge

A lookup can return a believable but wrong answer. If the source table contains the same customer ID twice, VLOOKUP returns the first matching row it finds. Sorting the table can change which row is first while the formula still looks healthy.

Prove that the key is duplicated

Select the source ID column and use conditional formatting to highlight duplicate values, or add =COUNTIF($A$2:$A$500,A2) beside it. A count greater than one means the lookup has a choice to make. Check whether those records truly duplicate each other or represent orders, revisions, or updates.

Choose a rule that matches the data

  • Newest: use a date field when the latest revision should win. Sort or calculate by that date explicitly.
  • First or last: use row order only if the order itself has meaning and will remain stable.
  • Total or count: aggregate when repeated IDs represent multiple transactions rather than competing customer records.
  • All rows: keep a list when each match needs separate review.

If none of these describes the records, stop and inspect the source. Removing duplicate rows automatically can destroy legitimate data.

XLOOKUP does not decide for you

XLOOKUP can search from the bottom to return the last matching value. It still needs you to decide whether “last” is correct. FILTER can return all matching rows; that is useful when every record matters, but it also moves the choice to the next step.

Review duplicate keys before merging

Match & Merge counts duplicate source IDs and shows how many destination rows they affect. It stops before a paid run when affected rows have more than one source match. You can explicitly choose the first or last source row; it does not silently copy VLOOKUP's first-match behavior. Supported destination XLSX workbooks retain their existing package features; incoming fields from another workbook are copied as values and supported number formats. Existing tables and chart ranges are not automatically expanded. Both input files stay unchanged.

Common questions

Should I remove duplicates first?

Only if they are accidental copies. Two invoices for one customer are not duplicate transactions, even though their customer ID repeats.

Can VLOOKUP return the last match?

Not with its ordinary exact-match behavior. XLOOKUP supports searching from last to first, but check that row order is a valid business rule before relying on it.

What if the lookup returns #N/A instead?

That is a separate issue. Use the #N/A diagnostic guide to check spaces, types, and IDs genuinely missing from the other list.

Check my matching IDs →