Using IF and VLOOKUP

camilleso

New Member
Joined
Aug 14, 2019
Messages
15
Can I have one formula with 2 vlookup search criterias? I have one list of IDs, list one contains CUST, second list does not. If IDs contain CUST, i want the vlookup to search one row of data to match and return values. If no CUST exists, i want the vlookup to search a different row of data to match and return values. Do I have to have 2 separate vlookups or can i combine them somehow?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Could you post some sample data and what you expect as a result(s)?
 
Upvote 0
Something similar to this.


Excel 2013/2016
ABCDEF
1Cust IDLookUpCust IDData1Data1
2Test1ATest1A
3Test2BTest2B
4Test3DTest3D
5Test4DTest4D
6Test5ETest5E
Sheet1
Cell Formulas
RangeFormula
B2=IF(VLOOKUP(A2,$D$2:$F$6,2,0)="",VLOOKUP(A2,$D$2:$F$6,3),VLOOKUP(A2,$D$2:$F$6,2,0))
 
Upvote 0
Sure! My expected result is to add the company type to sheet one which contain a list of ids with and without CUST at the beginning of the numeric value. sheet 2 contain the IDs in separate columns (one with numeric IDs and one that start with CUST); both of which have the company types. Can one formula be made to add company type on sheet one based on the ID match on sheet 2?

Columns on sheet 1
Company Type Account ID
12345
45678
91011
CUST-12345
CUST-45678
CUST-91011

Columns on sheet 2
Customer ID Customer ID (Deprecated) Company Type
12345 Network
45678 Agency
91011 Platform
CUST-12345 Publisher
CUST-45678 SSP
CUST-91011 Network
 
Upvote 0
How's this?

Code:
=VLOOKUP(A2,Sheet2!$A$2:$B$7,2,FALSE)

filled down in the B column on Sheet1

Sheet1


<colgroup><col style="mso-width-source:userset;mso-width-alt:3803;width:78pt" width="104"> <col style="width:48pt" width="64"> </colgroup><tbody>
[TD="class: xl65, width: 104, align: right"]12345[/TD]
[TD="class: xl65, width: 64"]Network[/TD]

[TD="class: xl65, align: right"]45678[/TD]
[TD="class: xl65"]Agency[/TD]

[TD="class: xl65, align: right"]91011[/TD]
[TD="class: xl65"]Platform[/TD]

[TD="class: xl65"]CUST-12345[/TD]
[TD="class: xl65"]Publisher[/TD]

[TD="class: xl65"]CUST-45678[/TD]
[TD="class: xl65"]SSP[/TD]

[TD="class: xl65"]CUST-91011[/TD]
[TD="class: xl65"]Network[/TD]

</tbody>

Sheet2


<colgroup><col style="mso-width-source:userset;mso-width-alt:5083;width:104pt" width="139"> <col style="mso-width-source:userset;mso-width-alt:3218;width:66pt" width="88"> </colgroup><tbody>
[TD="class: xl65, width: 139, align: right"]12345[/TD]
[TD="class: xl65, width: 88"]Network[/TD]

[TD="class: xl65, align: right"]45678[/TD]
[TD="class: xl65"]Agency[/TD]

[TD="class: xl65, align: right"]91011[/TD]
[TD="class: xl65"]Platform[/TD]

[TD="class: xl65"]CUST-12345[/TD]
[TD="class: xl65"]Publisher[/TD]

[TD="class: xl65"]CUST-45678[/TD]
[TD="class: xl65"]SSP[/TD]

[TD="class: xl65"]CUST-91011[/TD]
[TD="class: xl65"]Network[/TD]

</tbody>
 
Last edited:
Upvote 0
Something similar to this.

Excel 2013/2016
ABCDEF

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Cust ID[/TD]
[TD="align: center"]LookUp[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Cust ID[/TD]
[TD="align: center"]Data1[/TD]
[TD="align: center"]Data1[/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]Test1[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Test1[/TD]
[TD="align: center"]A[/TD]
[TD="align: center"][/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]Test2[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Test2[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"][/TD]

[TD="align: center"]4[/TD]
[TD="align: center"]Test3[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Test3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]D[/TD]

[TD="align: center"]5[/TD]
[TD="align: center"]Test4[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Test4[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"][/TD]

[TD="align: center"]6[/TD]
[TD="align: center"]Test5[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Test5[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]B2[/TH]
[TD="align: left"]=IF(VLOOKUP(A2,$D$2:$F$6,2,0)="",VLOOKUP(A2,$D$2:$F$6,3),VLOOKUP(A2,$D$2:$F$6,2,0))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
Sort of. Column A and D have different labels to represent the Cust IDs on sheet 2, although they both have lookup values I need. Sheet one has a combined list of Cust IDs from Column A and D (so A may have Test1 and D may have 1, although it represents the same Cust ID). If the value isn't found in column A, I will need to search D to return the Cust ID.
 
Upvote 0
One edit, to this:
Sort of. Column A and D have different labels to represent the Cust IDs on sheet 2, although they both have lookup values I need. Sheet one has a combined list of Cust IDs from Column A and D (so A may have Test1 and D may have 1, although it represents the same Cust ID). If the value isn't found in column A, I will need to search D to return the Client Type. Client Type is the lookup value I need returned for each Cust ID if it's labeled Test 1 or 1.
 
Upvote 0
Something like this.


Excel 2013/2016
ABCDEFG
1Cust ID-1C-TypeCust ID-2C-TypeCust IDLookup
212345NetworkCUST-12345Network12345Network
345678AgencyCUST-45678Agency45678Agency
491011PlatformCUST-91011Platform91011Platform
5PublisherPublisherCUST-12345Network
6SSPSSPCUST-45678Agency
7NetworkNetworkCUST-91011Platform
Sheet1
Cell Formulas
RangeFormula
G2=IFERROR(VLOOKUP(F2,$A$2:$B$7,2,0),VLOOKUP(F2,$C$2:$D$7,2,0))
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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