Lookup From a Column based on Multiple Criteria (in Columns)

Jon760

New Member
Joined
Jun 13, 2013
Messages
16
Hi folks,

Below is a visual of my problem. I have zips all listed in one row / several columns B:F (all zips are unique), I would like to have zip in Column J lookup the value in Column A, if it finds a zip that are in columns B:F. Do you have any suggestion? or maybe how I can simply copy-transpose the zip and replicate the city with the number of instances so that I can do a simple vlookup?

Thank you for whatever help of thoughts you may have.

 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here's a UDF you can try. Install the function then use it as in the example below. R is the entire data range, excluding the header row.
Excel Workbook
ABCDEFGHIJK
1CityZip
2Seattle980019801798057981689801097011Portland
3Portland970079709997011970579700192008San Diego
4San Diego921019200892084920819191998057Seattle
Sheet6



Code:
Function ZipCity(R As Range, Zip As Long) As String
Dim Fnd As Range
Set Fnd = R.Find(Zip)
If Fnd Is Nothing Then
    ZipCity = ""
Else
    ZipCity = Cells(Fnd.Row, R.Columns(1).Column).Value
End If
End Function
 
Upvote 0
Here's a UDF you can try. Install the function then use it as in the example below. R is the entire data range, excluding the header row.
Sheet6

ABCDEFGHIJK
CityZip
Seattle Portland
Portland San Diego
San Diego Seattle

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:26px;"><col style="width:19px;"><col style="width:16px;"><col style="width:42px;"><col style="width:68px;"></colgroup><tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]1[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]2[/TD]

[TD="align: right"]98001[/TD]
[TD="align: right"]98017[/TD]
[TD="align: right"]98057[/TD]
[TD="align: right"]98168[/TD]
[TD="align: right"]98010[/TD]

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

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]3[/TD]

[TD="align: right"]97007[/TD]
[TD="align: right"]97099[/TD]
[TD="align: right"]97011[/TD]
[TD="align: right"]97057[/TD]
[TD="align: right"]97001[/TD]

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

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]4[/TD]

[TD="align: right"]92101[/TD]
[TD="align: right"]92008[/TD]
[TD="align: right"]92084[/TD]
[TD="align: right"]92081[/TD]
[TD="align: right"]91919[/TD]

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

</tbody>

Spreadsheet Formulas
CellFormula
K2=zipcity($A$2:$F$4,J2)

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4


Code:
Function ZipCity(R As Range, Zip As Long) As String
Dim Fnd As Range
Set Fnd = R.Find(Zip)
If Fnd Is Nothing Then
    ZipCity = ""
Else
    ZipCity = Cells(Fnd.Row, R.Columns(1).Column).Value
End If
End Function


Thanks so much, it worked! Cheers to you man.
 
Upvote 0
Can you use something like this? You need to use Cntrl+Shift+Enter. Then copy down. Here is the formula [TABLE="width: 68"]
<tbody>[TR]
[TD="width: 68"] =INDEX($A$2:$A$4,SMALL(IF($B$2:$F$4=$J2,ROW($A$2:$A$4)-ROW($A$2)+1),1))

[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 708"]
<colgroup><col span="10"><col></colgroup><tbody>[TR]
[TD]City[/TD]
[TD]Zip[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Seattle[/TD]
[TD="align: right"]98001[/TD]
[TD="align: right"]98017[/TD]
[TD="align: right"]98057[/TD]
[TD="align: right"]98168[/TD]
[TD="align: right"]98010[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]97011[/TD]
[TD]Portland [/TD]
[/TR]
[TR]
[TD]Portland [/TD]
[TD="align: right"]97007[/TD]
[TD="align: right"]97099[/TD]
[TD="align: right"]97011[/TD]
[TD="align: right"]97057[/TD]
[TD="align: right"]97001[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]92008[/TD]
[TD]San Diego[/TD]
[/TR]
[TR]
[TD]San Diego[/TD]
[TD="align: right"]92101[/TD]
[TD="align: right"]92008[/TD]
[TD="align: right"]92084[/TD]
[TD="align: right"]92081[/TD]
[TD="align: right"]91919[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98057[/TD]
[TD]Seattle[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Can you use something like this? You need to use Cntrl+Shift+Enter. Then copy down. Here is the formula [TABLE="width: 68"]
<tbody>[TR]
[TD="width: 68"] =INDEX($A$2:$A$4,SMALL(IF($B$2:$F$4=$J2,ROW($A$2:$A$4)-ROW($A$2)+1),1))
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 708"]
<tbody>[TR]
[TD]City[/TD]
[TD]Zip[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Seattle[/TD]
[TD="align: right"]98001[/TD]
[TD="align: right"]98017[/TD]
[TD="align: right"]98057[/TD]
[TD="align: right"]98168[/TD]
[TD="align: right"]98010[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]97011[/TD]
[TD]Portland[/TD]
[/TR]
[TR]
[TD]Portland[/TD]
[TD="align: right"]97007[/TD]
[TD="align: right"]97099[/TD]
[TD="align: right"]97011[/TD]
[TD="align: right"]97057[/TD]
[TD="align: right"]97001[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]92008[/TD]
[TD]San Diego[/TD]
[/TR]
[TR]
[TD]San Diego[/TD]
[TD="align: right"]92101[/TD]
[TD="align: right"]92008[/TD]
[TD="align: right"]92084[/TD]
[TD="align: right"]92081[/TD]
[TD="align: right"]91919[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]98057[/TD]
[TD]Seattle[/TD]
[/TR]
</tbody>[/TABLE]

Fabulous! The INDEX formula worked, thanks Mike. What if I simply copy and paste those cities (Column A) to Column G and do a lookup, what would the formula be?
 
Upvote 0
Well, as I see it, given only the city name (and no number to distinguish the city), how would would the formula know which number to find? For example, the formula will recognize that 97007, 97099, 97011, 97057, and 97001 are tied to Portland.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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