Vlookup/IF question

biglb79

Active Member
Joined
Oct 17, 2007
Messages
303
Office Version
  1. 2019
Platform
  1. Windows
how would I create a formula to lookup an ID number in column C on a US directory tab or CA directory tab if the country code in column B is either US or CA? Below are the three columns I'm using and I want the file number to look in the specific directory tab based on what country code is used in column B

Country ID # File #
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Consider:

ABCDE
CountryID #File #
USaa
CAww
XXc

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

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

[TD="align: right"]1[/TD]

[TD="align: right"][/TD]

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

[TD="align: right"]2[/TD]

[TD="align: right"][/TD]

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

[TD="align: right"]3[/TD]
[TD="align: right"]#REF![/TD]

[TD="align: right"][/TD]

</tbody>
Sheet5

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]C2[/TH]
[TD="align: left"]=VLOOKUP(B2,INDIRECT(A2&"!A2:B10"),2,FALSE)[/TD]
[/TR]
[TR]
[TH]D2[/TH]
[TD="align: left"]=VLOOKUP(B2,INDIRECT(LOOKUP(A2,{"CA","US"},{"'CA Sheet'","'US Sheet'"})&"!A2:B10"),2,FALSE)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



If your tab names are the same as the state, then you can use the formula in C2. If you need to lookup the tab name based on the value in A2, then perhaps the D2 formula would work for you. Both formulas assume that your lookup table in in the same range on both sheets, A2:B10.

Note that if you use the second formula, the values in the first array {"CA","US"} must be in alphabetical order. Also, if you get a "not found" condition, like in row 4, it will use the last value in the array. So if you have a long list to work with, there might be better ways.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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