I want to use vlookup
but the column in the table that is to be searched has occasional entries with a trailing space. But vlookup
cannot find these because of the trailing space.
vlookup('Smith',tablename, columnnumber,TRUE) cannot find 'Smith '.
The table is from an external database that I cannot edit. Setting the third parameter of vlookup to FALSE
does not work either, although you would think that Smith
is the next closest thing to Smith
.
How about wrapping the tablename with the trim function. Be sure and enter the formula with CTRL + SHIFT + ENTER :
=vlookup('Smith',Trim(tablename), columnnumber,False)
You cannot wildcard your VLOOKUP function's lookup_value without risking a false positiove on Smithers when you are searching for Smith . However, the IFERROR function can pass control to an alternate VLOOKUP that appends a single space to the lookup_value .
=IFERROR(vlookup("Smith", tablename, columnnumber, FALSE), IFERROR(vlookup("Smith"&CHAR(32), tablename, columnnumber, FALSE), ""))
If Smith cannot be found then append a space character and try again. If it still fails, give up and pass back a zero-length string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.