Lookup max value in a group of matching row, but return text in adjacent column

AAMN2014

New Member
Joined
Oct 13, 2014
Messages
5
Hi Guys,

I've been scratching my head on this formula past few days.

How do I lookup a column with the highest value in a group of row? Example of table as below with the most right column the expected result of the formula (cant attach a file or past a picture, so the table might look a bit haywire).

I've been trying nesting Max/IF, with Index/Match, even with Vlookup functions, still not able to get a result I want.

I know if I wanted to get the Highest Loan Amount in each group, I'm able to use Max(IF) function, but not able to Index it and get the column adjacent to it.

Really hope you guys can help me out with this, have been bugging my work few days already. Thanks

1ABCDE
2GROUPLOAN AMTNAMEPerson with Highest Loan Amt in each groupExpected Result
3A$10Amy Alex
4A$15Adam Alex
5A$20Alex Alex
6B$25Bryan Barry
7B$30Barney Barry
8B$35Barry Barry
9C$40Cathy Candice
10C$45Cammy Candice
11C$50Candice Candice

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

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Let's break this down.

To find the max in a range:
Code:
=Max(B3:B6)

To return the position in a range where the max appears:
Code:
=MATCH(Max(B3:B6), B3:B6,0)-1

To return the cell next to it:
Code:
=Offset(B3, Match(Max(B3:B6),B3:B6,0)-1,1)

Now all that remains is to match the group to a range of rows:
To find the beginning of the range:
Code:
 =MATCH("A", A:A,0)
To find the end of the range:
Code:
 =MATCH("A", A:A,0)+Countif(A:A, "A")-1

Putting it all together:

Code:
=Offset(INDIRECT("B" & MATCH("A", A:A,0)), Match(Max(INDIRECT("B" & MATCH("A", A:A,0) & ":B" & MATCH("A", A:A,0)+Countif(A:A, "A")-1)),INDIRECT("B" & MATCH("A", A:A,0) & ":B" & MATCH("A", A:A,0)+Countif(A:A, "A")-1),0)-1,1)

Hope that helps,

Kind Regards,
Chris

n.b. Make sure that in column B you have just numbers btw :)
 
Last edited:
Upvote 0
GROUPLOAN AMTNAMEPerson with Highest Loan Amt in each group
A$20 AmyAmy, Alex
A$15 AdamAmy, Alex
A$20 AlexAmy, Alex
B$25 BryanBarry
B$30 BarneyBarry
B$35 BarryBarry
C$40 CathyCandice
C$45 CammyCandice
C$50 CandiceCandice

<COLGROUP><COL style="WIDTH: 64pt; mso-width-source: userset; mso-width-alt: 3043" width=86><COL style="WIDTH: 87pt; mso-width-source: userset; mso-width-alt: 4124" width=116><COL style="WIDTH: 67pt; mso-width-source: userset; mso-width-alt: 3157" width=89><COL style="WIDTH: 266pt; mso-width-source: userset; mso-width-alt: 12629" width=355><TBODY>
</TBODY>

D2, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=REPLACE(aconcat(IF($A$2:$A$10=$A2,IF($B$2:$B$10=MAX(IF($A$2:$A$10=$A2,$B$2:$B$10)),
  ", "&$C$2:$C$10,""),"")),1,2,"")

ACONCAT is a VBA function, which you need to install as a module in your workbook, using Alt+F11...

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
 
Upvote 0
Thanks a lot, Chris & Aladin!

Chris, i tried your formula, unfortunately it's returning #N/A in the resulting column.

Aladin, I've created the ACONCATE module in VBA, unfortunately the resulting column is showing blank.

Appreciate all the help you guys can give on this. Thanks again!

1ABC DE
2GROUPLOAN AMTNAMEMethodPerson with Highest Loan Amt in each groupExpected Result
3A$10AmyAladin Alex
4A$15AdamChris#N/AAlex

<colgroup><col><col><col><col span="2"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Wow! It works like a charm! I just realize my mistake in trying this out before, my workbook still had the "A-B-C-D-E & 1-2-3-4-5-6-7-8-9" taking up 1 row and 1 column that making the formula not match.

Thanks Aladin! Really out of the box solution, and taught me something new. Cheers!

1ABC DE
2GROUPLOAN AMTNAMEMethodPerson with Highest Loan Amt in each groupExpected Result
3A$10AmyAladin Alex
4A$15AdamChris#N/AAlex
5A$20Alex Alex
6B$25Bryan Barry
7B$30Barney Barry
8B$35Barry Barry
9C$40Cathy Candice
10C$45Cammy Candice
11C$50Candice Candice

<colgroup><col><col><col><col span="2"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Wow! It works like a charm! I just realize my mistake in trying this out before, my workbook still had the "A-B-C-D-E & 1-2-3-4-5-6-7-8-9" taking up 1 row and 1 column that making the formula not match.

Thanks Aladin! Really out of the box solution, and taught me something new. Cheers!
...

You are welcome. I don't understand the exhibit you post for it's not what the set up I posted would return!...
 
Upvote 0
If you can rely on the data being sorted, what about, in D2 and copy down,
Code:
=IF(A2<>A3,C2,D3)
 
Upvote 0
You are welcome. I don't understand the exhibit you post for it's not what the set up I posted would return!...

Aladin, it was a stupid mistake on my part. But your solution is working perfectly how I wanted!

Below is the latest return I got by using your solution. When I tried your solution the first time, I forgot to remove the dummy row & column I created just to paste the table in this forum. So when I copy exactly the formula that you gave, it wasn't reading the right column.

But when I got your workbook, together with the VBA module you sent, I realized I forgot to remove it.

Anyway, thanks again.

GROUPLOAN AMTNAMEPerson with Highest Loan Amt in each group
A$10AmyAlex
A$15AdamAlex
A$20AlexAlex
B$25BryanBarry
B$30BarneyBarry
B$35BarryBarry
C$40CathyCandice
C$45CammyCandice
C$50CandiceCandice

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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