Function Problems

Fix Excel VLOOKUP for Extra Spaces and Partial City Names

John WilsonJohn Wilson Nov 18, 2026 869 views

Question details

Find rates for city names when extra spaces or state names prevent an exact VLOOKUP match.

Fix Excel VLOOKUP for Extra Spaces and Partial City Names
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains city names, while a Rates lookup table may contain the same cities followed by state names.
Observed behavior
VLOOKUP can return an error when the lookup value and the city text in the Rates table do not match exactly.
Before you start

Check that the city is in B3 and that Rates!A1:B1147 contains the lookup text in column A and the corresponding rate in column B. Adjust the cell references and range if your workbook is arranged differently.

Solution 1Recommended

Use TRIM and wildcards to match partial city names

Use this approach when B3 contains a city and the Rates table includes that city with additional text, such as a state.

1
Enter the lookup formula

Select the cell where you want the rate and enter =IF(TRIM(B3)="","",VLOOKUP("*"&TRIM(B3)&"*",Rates!$A$1:$B$1147,2,FALSE)).

2
Fill the formula down

Press Enter, then drag the cell's fill handle down to look up the other cities in column B.

3
Check the matches

Compare returned rates with the city and state entries on the Rates sheet, especially where city names are similar.

Use TRIM and wildcards to match partial city names
Partial matches return the first result: The asterisks match text before or after the city, so VLOOKUP returns the first matching row. A partial city name can match an unintended entry; include the state in the lookup when you need to distinguish locations.
Work with spreadsheets in WPS Office

Match City Names with VLOOKUP in WPS Spreadsheets

Use TRIM and wildcard VLOOKUP in WPS Spreadsheets to find rates when city names contain extra spaces or the lookup table also includes states.

  1. 1. Open the workbook: Open WPS Spreadsheets and choose Open to select your Excel workbook.
  2. 2. Check the lookup range: Open the Rates sheet and confirm that column A contains city text and column B contains rates.
  3. 3. Enter the formula: On the sheet containing the city in B3, select a result cell and enter =IF(TRIM(B3)="","",VLOOKUP("*"&TRIM(B3)&"*",Rates!$A$1:$B$1147,2,FALSE)).
  4. 4. Fill and verify: Drag the formula's fill handle down, then check the returned rates against the matching entries on the Rates sheet.
Match partial city names with familiar VLOOKUP formulasOpen and edit Microsoft Excel XLSX and XLS filesClean imported city names with TRIMFill lookup formulas down a worksheet
microsoft office alternative - wps office

Frequently Asked Questions

Why does VLOOKUP return #N/A for a city that appears in the table?

An exact lookup requires the text to match. Extra spaces or a state suffix can cause a mismatch. Use TRIM for ordinary spaces and a wildcard lookup when the table contains additional text.

How do I remove extra spaces from imported city names?

Enter =TRIM(A1) in an empty cell and fill the formula down. To replace the original text, copy the results and use Paste Special > Values over the original cells.

Why didn't TRIM remove all the spaces?

TRIM does not remove nonbreaking spaces commonly found in imported text. Try =TRIM(SUBSTITUTE(A1,CHAR(160)," ")) in a helper column, then fill it down.

What happens if more than one city matches the wildcard lookup?

VLOOKUP returns the first matching row in the lookup range. Check the Rates sheet and include the state or use a more specific lookup value when cities have similar names.