vlookup with if or where clause

I have a vlookup that I am trying to make it a little more functional:

=VLOOKUP(Q2,IP!A:BA,2,FALSE)

This pulls back some of the data that i need.  

However, i want it to be more exact.  I need it to only pull back the data if the data in another column in sheet IP contains the word 'last'

so basically i need something like this:

The table example is below.  Of course, with my simple code about I just pull back a 1 every time ColumnA has a 2.  However, I only want to pull back the match where the first match happens.

COLUMNa      COLUMNb     COLUMNc
2                       1
2                       1,2
2                       1,2,3
2                       1,2,3,4            Last   <-------i just want this one to populate when there is a 2 in my vlookup formula
3                       a
3                       a,b
3                       a,b,c                Last   <-------i just want this one to populate when there is a 3 in my vlookup formula


Thanks
farmingtonisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try  as Array formula Ctrl-Shift-Enter

=INDEX(B1:B9,MATCH(1,(A1:A9=2)*(C1:C9="Last")))

Regards
0
Glenn RayExcel VBA DeveloperCommented:
I suspect that this can be simplified, but I tested it and it works:
=IFERROR(INDEX(IP!A:B,MATCH(Q2,IP!A:A,0)+MATCH("Last",OFFSET(IP!$C$1,MATCH(Q2,IP!A:A,0)-1,,COUNTIF(IP!A:A,Q2),),0)-1,2),"")

Note:  The word "Last" must be in column C and the formula doesn't care if "Last" actually is on the final row of a section of data.

See attached example file.  

Regards,
-Glenn
EE-Q28500856.xlsx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Glenn RayExcel VBA DeveloperCommented:
IF you always want the final value in the IP sheet for any specific value in column A - regardless of if the word "Last" is there - this formula is much simpler:
=IFERROR(INDEX(IP!A:B,MATCH(Q2,IP!A:A,0)+COUNTIF(IP!A:A,Q2)-1,2),"")

I've updated the example file with both formulas for comparison.

-Glenn
EE-Q28500856.xlsx
0
farmingtonisAuthor Commented:
This one did the trick.  THank you
0
Glenn RayExcel VBA DeveloperCommented:
You're welcome.  Of course, that second formula would mean that you wouldn't even need the "Last" indicator column, but I'm glad it works!

-Glenn
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.