rahmanafzal

New Member
Joined
Jun 21, 2018
Messages
1
Needs help in order to match longest prefix, As an example


I have an excel which contains prefix list like below; Column A contains regions and Column B contains prefix.


Destination Prefix
Afghanistan 93
Afghanistan - Mobile - Afghan Telecom 9375
Afghanistan - Mobile - Awcc 9370
Afghanistan - Mobile - Awcc 9371
Afghanistan - Mobile - Etisalat 9378
Afghanistan - Mobile - Mtn 9376
Afghanistan - Mobile - Mtn 93765
Afghanistan - Mobile - Mtn 93766
Afghanistan - Mobile - Mtn 93767
Afghanistan - Mobile - Mtn 9377
Afghanistan - Mobile - Roshan 9372
Afghanistan - Mobile - Roshan 93744
Afghanistan - Mobile - Roshan 93747
Afghanistan - Mobile - Roshan 9379
Afghanistan - Mobile - Salaam 9374




and Column D contains dialed numbers list, Now what i need is to match the dialed number which is in column D with longest prefix match with column B and return the value of Column A against the match and put in Column E as shown below.


like 93774841931 is longest prefix match 9377 which returns the value "Afghanistan - Mobile - Mtn" in column E.
Dialed Number Region
93774841931 Afghanistan - Mobile - Mtn
93705713317 Afghanistan - Mobile - Awcc
93705713317 Afghanistan - Mobile - Awcc
93787469021 Afghanistan - Mobile - Etisalat
93778513480 Afghanistan - Mobile - Mtn
93778513480 Afghanistan - Mobile - Mtn
93778513480 Afghanistan - Mobile - Mtn
93767195343 Afghanistan - Mobile - Mtn




Regards,
Rahman
 
Last edited by a moderator:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Welcome to the Board.

Try:

ABCDEF
1Destination Prefix
2Afghanistan9393774841931Afghanistan - Mobile - Mtn
3Afghanistan - Mobile - Afghan Telecom937593705713317Afghanistan - Mobile - Awcc
4Afghanistan - Mobile - Awcc937093705713317Afghanistan - Mobile - Awcc
5Afghanistan - Mobile - Awcc937193787469021Afghanistan - Mobile - Etisalat
6Afghanistan - Mobile - Etisalat937893778513480Afghanistan - Mobile - Mtn
7Afghanistan - Mobile - Mtn937693778513480Afghanistan - Mobile - Mtn
8Afghanistan - Mobile - Mtn9376593778513480Afghanistan -Mobile - Mtn
9Afghanistan - Mobile - Mtn9376693767195343Afghanistan - Mobile - Mtn
10Afghanistan - Mobile - Mtn93767
11Afghanistan - Mobile - Mtn9377
12Afghanistan - Mobile - Roshan9372
13Afghanistan - Mobile - Roshan93744
14Afghanistan - Mobile - Roshan93747
15Afghanistan - Mobile - Roshan9379
16Afghanistan - Mobile - Salaam9374

<tbody>
</tbody>
Sheet12

Array Formulas
CellFormula
E2{=IFERROR(INDEX($A$2:$A$16,MOD(LARGE(IF(LEFT(D2,LEN($B$2:$B$16))=$B$2:$B$16&"",LEN($B$2:$B$16)*10000+ROW($B$2:$B$16)),1),10000)-ROW($B$2)+1),"")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,904
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top