If and Vlookup with Multiple Criteria

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
922
Office Version
  1. 365
Hi,

I have a list of data where the letters starts with the list in the table below in column Category. I need to insert a formula to return as the column "Then". I tried If and LEFT but I am not sure to cater for the long list .
Is there a way have a formula for this ? Appreciate all the help.

Table 1

Excel Workbook
BC
2CategoryThen
3RFPolice
4IPolice
5GPolice
6MOld IC
7AOld IC
8A plus any alphabetBC
9EBC
10JBC
11BBC
12CBC
13FBC
14SSingapore
15TArmy
16DummyMigration
17KBC
18LBC
19NNavy
20PPassport
21QBC
22UPassport
23XPassport
24YPassport
25ZPassport
Sheet1


Sample Data and The Correct Return Value
Excel Workbook
EF
2Sample DataReturn As
3RF1254Police
4I44775Police
5G4557Police
6M4555Old IC
7A4558Old IC
8AC11225BC
9E455578BC
10J4558BC
11B4585BC
12C55887BC
13F2554BC
14S22554Singapore
15T22554Army
16Dummy4558Migration
17K5558BC
18L55558BC
19N5558Navy
20P2255Passport
21Q55587BC
22U55587Passport
23X22554Passport
24Y5558Passport
25Z5558Passport
Sheet1
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Sort A:B on A in ascending order.

In F2 enter and copy down:

=LOOKUP(9.99999999999999E+307,SEARCH($A$2:$A$24,$E2),$B$2:$B$24)
 
Upvote 0
The following would take the presence of " plus any alphabet" into account...

=LOOKUP(9.99999999999999E+307,SEARCH(SUBSTITUTE($A$2:$A$24," plus any alphabet","?"),$E2),$B$2:$B$24)
 
Upvote 0
Hi Aladin,

I am not sure if I understood you correctly. I have tried the formula but it does not return the correct values. My apologies if I am doing this wrongly.

Excel Workbook
ABCDEF
2CategoryThenSample DataReturn As
3ARFPoliceRF1254N
4A plus any alphabetIPoliceI44775B
5BGPoliceG4557J
6CMOld ICM4555T
7DummyAOld ICA4558I
8EA plus any alphabetBCAC11225M
9FEBCE455578A plus any alphabet
10GJBCJ4558C
11IBBCB4585G
12JCBCC55887M
13KFBCF2554E
14LSSingaporeS22554P
15MTArmyT22554Q
16NDummyMigrationDummy4558Y
17PKBCK5558F
18QLBCL55558S
19RFNNavyN5558Dummy
20SPPassportP2255K
21TQBCQ55587L
22UUPassportU55587U
23XXPassportX22554X
24YYPassportY5558Y
25ZZPassportZ5558Z
Sheet1
 
Upvote 0
this is how Aladin's post#2 works


Excel 2013/2016
ABCDEF
1Sample DataReturn As
2AOld ICRF1254Police
3A 123BCI44775Police
4BBCG4557Police
5CBCM4555Old IC
6DummyMigrationA4558Old IC
7EBCAC11225BC
8FBCE455578BC
9GPoliceJ4558BC
10IPoliceB4585BC
11JBCC55887BC
12KBCF2554BC
13LBCS22554Singapore
14MOld ICT22554Army
15NNavyDummy4558Passport
16PPassportK5558BC
17QBCL55558BC
18RFPoliceN5558Navy
19SSingaporeP2255Passport
20TArmyQ55587BC
21UPassportU55587Passport
22XPassportX22554Passport
23YPassportY5558Passport
24ZPassportZ5558Passport
Sheet1
Cell Formulas
RangeFormula
F2=LOOKUP(9.99999999999999E+307,SEARCH($A$2:$A$24,$E2),$B$2:$B$24)
 
Upvote 0
.......... deleted
 
Last edited:
Upvote 0
unfortunately, it didn't work for the "Dummy" entry


Excel 2013/2016
ABCDEF
1Sample DataReturn As
2AOld ICRF1254Police
3ABBCI44775Police
4BBCG4557Police
5CBCM4555Old IC
6DummyMigrationA4558Old IC
7EBCAC11225BC
8FBCE455578BC
9GPoliceJ4558BC
10IPoliceB4585BC
11JBCC55887BC
12KBCF2554BC
13LBCS22554Singapore
14MOld ICT22554Army
15NNavyDummy4558Passport
16PPassportK5558BC
17QBCL55558BC
18RFPoliceN5558Navy
19SSingaporeP2255Passport
20TArmyQ55587BC
21UPassportU55587Passport
22XPassportX22554Passport
23YPassportY5558Passport
24ZPassportZ5558Passport
Sheet1
 
Upvote 0
Hi Aladin,

I am not sure if I understood you correctly. I have tried the formula but it does not return the correct values. My apologies if I am doing this wrongly.

[...]

unfortunately, it didn't work for the "Dummy" entry

[...]

AlanY: Thanks for catching that.

In F2 enter and copy down:

=LOOKUP(9.99999999999999E+307,SEARCH(SUBSTITUTE("|"&$A$2:$A$24," plus any alphabet","?"),"|"&$E2),$B$2:$B$24)

Here is the workbook that implements the suggestion: https://www.dropbox.com/s/1t1dsuybj5xkj02/kumara_faith%20LOOKUP%2BSEARCH.xlsx?dl=0
 
Upvote 0
Hi AlanY and Aladin,

Thank you for the assistance. Appreciate it.

The following is the table from Aladin's worksheet. In the Category, if the data starts with A + any alphabets such as AC11225, then the formula should return as BC.But if the data only has A with numeric without any alphabet such as A4558 , then the formula should return as Old IC. In the table below, A4558 is returning as BC when it should return as Old IC. I am not sure how to rectify this. Appreciate the help and my apologies.

Excel Workbook
ABCDEF
1CategoryThenSample Data
2AOld ICRF1254Police
3A plus any alphabetBCI44775Police
4BBCG4557Police
5CBCM4555Old IC
6DummyMigrationA4558BC
7EBCAC11225BC
8FBCE455578BC
9GPoliceJ4558BC
10IPoliceB4585BC
11JBCC55887BC
12KBCF2554BC
13LBCS22554Singapore
14MOld ICT22554Army
15NNavyDummy4558Migration
16PPassportK5558BC
17QBCL55558BC
18RFPoliceN5558Navy
19SSingaporeP2255Passport
20TArmyQ55587BC
21UPassportU55587Passport
22XPassportX22554Passport
23YPassportY5558Passport
24ZPassportZ5558Passport
25AdBC
Sheet1
 
Upvote 0
Control+shift+enter, not just enter, and copy down:

=LOOKUP(9.99999999999999E+307,SEARCH("|"&IF(ISNUMBER(MID($E2,2,1)+0),$A$2:$A$24,SUBSTITUTE($A$2:$A$24," plus any alphabet","?")),"|"&$E2),$B$2:$B$24)
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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