VLOOKUP from a range matching multiple criteria

merce333

New Member
Joined
Jun 4, 2016
Messages
21
Hello. I've been struggling with this all morning. I had the following sheet that worked fine.
The user enters SUBJECT STATE, in this case KY for Kentucky.
Below there is a table called, "FullCompDataSet", with 3 columns.
I need to do 2 things from this data (output shown below in red):
A. Count the number of records in FullCompDataSet whose "ST/Prov" match the SUBJECT STATE. I had this formula:
Code:
=COUNTIF(FullCompDataSet[ST/Prov],SubjectStateAbbreviation)

B. Return the Key for each record. I had this formula:
Code:
{=SMALL(IF(FullCompDataSet[ST/Prov]=SubjectStateAbbreviation,FullCompDataSet[Key]),ROW()-18)}

All of that worked fine, but now instead of simply matching the Subject State to the St/Prov, I have a list of compatible states I need to match (example list at bottom in blue). So, the new output I need is:
A. 6 (because the subject state KY matches records in states of KY, IN, and TN)
B. 413, 420, 434, 418, 404, 410

Can anyone suggest the new formulas I'd need to use for A and B?? I've tried all sorts of combinations of VLOOKUP/INDEX/MATCH, OFFSET, INDIRECT but haven't been able to get it. My apologies if there was a better way to post this issue, I'm still learning to post. THANK YOU!

SUBJECT STATEKY
KeyAddressST/Prov
4132481 W. Sherman KY
5011867 Broadway St. CA
420563 Allen Rd. IN
4223677 South Pere Marquette Hwy MI
4342234 Glover Rd. KY
4181310 Fleming Ave. KY
4313801 New Tampa Hwy. FL
404Clay Ave. TN
4015450 N. Paramount Blvd. CA
3864264 SE. 122nd St. OR
4103323 NE. 14th Street TN
TOTAL RECORDS IN COMPATIBLE STATES3
KEY RECORDS413
418
434

<colgroup><col><col><col></colgroup><tbody>
</tbody>


StateCompatible States
ALAL
CTCT
CTME
FLFL
KYKY
KYIN
KYTN
TXTX

<colgroup><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
if you have a spare column, mayb a bit of vba to run down your main list and for every KY, IN, TN add in the spare column KY, then use that for your reference
 
Upvote 0
Thanks for the quick reply, mole!
- Spare columns I have. I'm under a "no VBA" restriction =(
- I believe a complication with that method is the fact that other states, for example, Ohio, may also have a compatible list that include TN, IN, and even KY.
I can envision individual steps on how to solve this, but I don't know how to make the corresponding formulas. Here is how I'm thinking in my head:
1. Do a VLOOKUP on the Subject State / Compatible State list based on the Subject State. This would leave me with this 'filtered' range:
StateCompatible States
KYKY
KYIN
KYTN

<colgroup><col><col></colgroup><tbody>
</tbody>

2. Next, do a COUNTIF where Subject State matches any entry in the 2nd column of the Compatible States list.
3. Finally, return all matching Key records where Subject State matches any entry in the 2nd column of the Compatible States list.
 
Upvote 0
Mole: I solved this using your suggestion of adding a column - Thank you. I actually added in a concatenated SubjectState&CompState column into the Compatible State List. Then I added in an identical column of concatenated SubjectState&CompState into each row of my FullCompDataSet. That way my old formulas now work the same way because these 2 new columns are a unique match just like the single-entity "ST/Prov" was before.
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,152
Latest member
PressEscape

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