简体   繁体   中英

Vlookup partial number in Excel

I'm trying to use a vlookup on telephone numbers by looking for the last 8 characters as some are begin 4401 and others just 1.

This is what I have so far:

=IFERROR(VLOOKUP("*"&(TRUNC(RIGHT(A3*1,8),0)*1),J:N,5,FALSE),"Unknown")

Column J contains the phone number and column N contains the source of the call (which is what I'm trying to extract).

The problem I have is that the iferror 'Unknown' is being returned. If I change the numbers to words then it works, it seems that it's numbers that are the problem. Any ideas?

Are you willing and able to modify the lookup spreadsheet structure slightly to add a Column K using the formula below in cell K1 and dragging that down??

=TEXT(J1,0)

Then your VLOOKUP will now see text instead of numbers. Therefore the wildcard will work. Just make sure to move your range accordingly (J:N to K:O).

=IFERROR(VLOOKUP("*"&(TRUNC(RIGHT(A3*1,8),0)*1),K:O,5,FALSE),"Unknown")

Edit: If you do not wish to modify your structure (probably best not to but case by case), this array formula will do the job. Make sure you hit Ctrl+Shift+Enter after entering the formula. If you don't, everything will return "Unknown". Ctrl+Shift+Enter is how Excel knows it is an array function.

=IFERROR(INDEX($N:$N,MATCH("y",IF(RIGHT(A3,8)=RIGHT($J:$J,8),"y",),0)),"Unknown")

With this latter method, you may want to set some sort of bound on your $J:$J range in order to speed up the function so it isn't checking every row in that column. Pick something bigger than your data will ever be (eg, $J$1:$J$50000).

This works for me:

{=INDEX($N$1:$N$4,MATCH(A3&"",RIGHT($J$1:$J$4,8),0),1)}

You need to enter it as an array formula - so control + enter after keying in the formula.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM