Vlookup with if function

censo

Board Regular
Joined
Dec 25, 2015
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
Hello,

I'd like assistance with figuring out how to determine the name of a carrier based on how the first few characters of a tracking ID begin with. The problem is some characters can instantly identify a carrier by the first character and other can be identified by 2 or 3 characters.

Lastly, if none of the criteria match, instead of outputting an N/A value, I'd prefer it to default to "FedEx".

The source data is column C "Tracking ID"

Columns H:I is a named range to be used in the function, entitled "CARRIER_TBL"

Column A "Carrier" is the intended output.

Observe how Lasership can be identified as either "1LS" or "LS", and

UPS can be identified with either "1Z" or "Z"

Lastly, "FedEx" was the correct output when the tracking ID for C8 could not be found (because FedEx has so many different variations to their tracking IDs, this is the preferred catch-all method)
Book1
ABCDEFGHI
1CarrierTracking IDCARRIER_TBL
2Lasership1LS5632108653421LSLasership
3LasershipLS720841130957LSLasership
4UPS1ZE3362503660903491ZUPS
5UPSZE336250366090349ZUPS
6United Delivery ServiceWM6280000000919759COnTrac
7OnTracC11659806311237WMUnited Delivery Service
8FedEx429154527459
Sheet2
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
In A2 enter and copy down:

=IFERROR(LOOKUP(9.99999999999999E+307,SEARCH("|"&$H$2:$H$7,"|"&$C2),$I$2:$I$7),"FedEx")
 
Upvote 0
In A2 enter and copy down:

=IFERROR(LOOKUP(9.99999999999999E+307,SEARCH("|"&$H$2:$H$7,"|"&$C2),$I$2:$I$7),"FedEx")

Oh boy, the problem is I've only situated the lookup table where it is for demonstration purposes only. The real array will reside on another "Reference" tab, that's why I preferred to have it a named range vs. hard coding it in because then it wouldn't matter where it resides.

I'll attempt to modify your solution to its new location and see if I can get that to work.

Thanks
 
Upvote 0
Oh boy, the problem is I've only situated the lookup table where it is for demonstration purposes only. The real array will reside on another "Reference" tab, that's why I preferred to have it a named range vs. hard coding it in because then it wouldn't matter where it resides.

I'll attempt to modify your solution to its new location and see if I can get that to work.

Thanks

If CARRIER_TBL refers to the 2-column table...

=IFERROR(LOOKUP(9.99999999999999E+307,SEARCH("|"&INDEX(CARRIER_TBL,0,1),"|"&$C2),INDEX(CARRIER_TBL,0,2)),"FedEx")

will do just as well.
 
Last edited:
Upvote 0
I'll attempt to modify your solution to its new location and see if I can get that to work.

Ok, so far so good. I modified the function to point to the new location of the array and it's working like a charm.

I'd like one slight modification and that is to not generate "FedEx" when there is no data present (in other words, remain blank).

What would the new function look like? This is what I've modified the function to in my production environment and is working good.

=IFERROR(LOOKUP(9.99999999999999E+307,SEARCH("|"&INDEX(CARRIER_TBL,0,1),"|"&$G2),INDEX(CARRIER_TBL,0,2)),"FedEx")
 
Last edited:
Upvote 0
We need to test G2 for being blank...



Nailed it.

There was just a C2 cell reference I had to correct to G2, but that most definitely did the trick. Thank you much and this thread may be considered 'ANSWERED'​
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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