Fix Excel VLOOKUP for Extra Spaces and Partial City Names
Question details
Find rates for city names when extra spaces or state names prevent an exact VLOOKUP match.

- 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.
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.
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.
Select the cell where you want the rate and enter =IF(TRIM(B3)="","",VLOOKUP("*"&TRIM(B3)&"*",Rates!$A$1:$B$1147,2,FALSE)).
Press Enter, then drag the cell's fill handle down to look up the other cities in column B.
Compare returned rates with the city and state entries on the Rates sheet, especially where city names are similar.

Clean both columns for an exact VLOOKUP match
Use exact matching when the lookup value and the Rates entries should contain the same city text after spaces are removed.
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. Open the workbook: Open WPS Spreadsheets and choose Open to select your Excel workbook.
- 2. Check the lookup range: Open the Rates sheet and confirm that column A contains city text and column B contains rates.
- 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. Fill and verify: Drag the formula's fill handle down, then check the returned rates against the matching entries on the Rates sheet.

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.




