Fix Excel VBA VLOOKUP Errors and Duplicate Name Matches
Question details
Find the correct record with VLOOKUP in VBA when names contain spaces or first names are duplicated.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A workbook looks up names on another sheet and needs an exact match for each person.
- Observed behavior
- The lookup may return #N/A or #VALUE!, or match the wrong person when the lookup key is not unique.
Check which columns contain the lookup names and return values on each sheet. Confirm that the lookup key is in the first column of the VLOOKUP table range.
Use an Exact-Match VLOOKUP in Excel VBA
Use this approach when the complete lookup value is available and you want VBA to handle a missing match.
The example uses A2 on a sheet named Lookup as the key and searches Time!A2:B12. Change the sheet names, cells, and range to match your workbook.
In Lookup!B2, test =VLOOKUP(A2,Time!$A$2:$B$12,2,FALSE). The final FALSE requires an exact match.
In the Visual Basic editor, add this code to a macro: Dim result As Variant result = Application.VLookup(Worksheets("Lookup").Range("A2").Value, Worksheets("Time").Range("A2:B12"), 2, False) If IsError(result) Then Worksheets("Lookup").Range("B2").Value = "Not found or lookup error" Else Worksheets("Lookup").Range("B2").Value = result End If
Run the macro from the Visual Basic editor and compare Lookup!B2 with the corresponding record on the Time sheet. If it reports an error, check the key and table range.

Create Consistent Full-Name Lookup Keys
Use a combined first-and-last-name key when first names are duplicated or spacing differs between sheets.
Work with Name Lookups in WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar interface for opening Excel workbooks and working with lookup formulas. Move compatible spreadsheets into WPS Spreadsheet and test any VBA macros separately, as macro support may vary.

Frequently Asked Questions
Why does VLOOKUP return #N/A for a name that appears on the other sheet?
Check the complete lookup value against the first column of the table range. Extra spaces, nonbreaking spaces, or other hidden characters can prevent an exact match. Use FALSE as the final VLOOKUP argument.
What happens if two rows have the same lookup name?
VLOOKUP returns the first matching row. Combine first and last names in a helper column, or add a unique identifier if full names are also duplicated.
How can I handle a missing VLOOKUP match in VBA?
Assign the result of Application.VLookup to a Variant and check it with IsError before writing the result to a worksheet cell.
Why does the lookup return the wrong column or a #VALUE! error?
Check the VLOOKUP table range and column index. The index must be a valid positive number within the range, and the lookup key must be in the range's first column.




