Looking up minimum value position in a range subset

A      2
 A      6
 A      12
 B      1
 B      2
 B      3


 How could I write up an array function in Excel to return the position of the row in a subset A, where the second column is the closest to number 5?

 I'm thinking of something along the lines of {=MATCH(1, IF(AND(A:A="A",B:B=MIN(IF(A:A="A",ABS(B:B-5),999))),1,0),0)}

 Hope the above makes sense.

 Thanks
saulius88AnalystAsked:
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.

Saurabh Singh TeotiaCommented:
You Okay with a user defined function for the same??

Saurabh...
0
saulius88AnalystAuthor Commented:
I would much prefer an array function - a UDF would make sharing an issue, it also is less "tidy".
0
saulius88AnalystAuthor Commented:
Sorry, I should have added, the expected result is "2" - i.e. second row.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

ProfessorJimJamCommented:
you can simply do this with array formula =MATCH(MIN(IF(A1:A6="A",B1:B6)),B1:B6,0)

press with control shift enter.

see the attached example
Book1.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
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Maybe this.....(Array Formula)

=MIN(IF(A2:A7="A",ABS(B2:B7-5)*(ROW(A2:A7)-ROW(A2)+1)))

Open in new window


That will give you the row number of A subset where corresponding value in col. B is closest to 5.

I think this is what you asked in your question.

Does this help?
1
ProfessorJimJamCommented:
i did not see the criteria of closest to 5.  

the formula from sktneer perfectly works for you
0
saulius88AnalystAuthor Commented:
Really helpful, thank you.
0
saulius88AnalystAuthor Commented:
Sorry, sktneer, I was testing out the solution that ProfessorJimJam provided before I saw your posts. Both solutions would work, I suppose. Thanks both.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
No problem.

But you wrote this.....

How could I write up an array function in Excel to return the position of the row in a subset A, where the second column is the closest to number 5?
What was that?

If that was your requirement, how could you get the correct output with the formula suggested by ProfessorJimJam?
0
saulius88AnalystAuthor Commented:
I tweaked the formula slightly, before seeing your solution:
=MATCH(MIN(IF(A1:A6="A",ABS(B1:B6-5))),ABS(B1:B6-5),0)

Since both your formulas work and were submitted before I hit "accept" I will request that the points are split.

Thanks again.
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.