VBA Code to find max value from horizontal text from list having numbers

jackt05

Board Regular
Joined
Feb 1, 2009
Messages
194
Dear All,

I have the following names in a row like below


[TABLE="align: center"]
<tbody>[TR]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]Sam[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]John[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]Jack[/TD]
[TD="width: 77, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]George Paul[/TD]
[TD="width: 71, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]Mathew Joy[/TD]
[/TR]
</tbody>[/TABLE]



and I have a table on another sheet where I have the following data,

<!-- Please do not remove this header -->


[TABLE="align: center"]
<tbody>[TR]
[TD="width: 81, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]Sam[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"]45[/TD]
[/TR]
[TR]
[TD="width: 81, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]John[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"]60[/TD]
[/TR]
[TR]
[TD="width: 81, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]Jack[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"]30[/TD]
[/TR]
[TR]
[TD="width: 81, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]George Paul[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"]85[/TD]
[/TR]
[TR]
[TD="width: 81, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]Mathew Joy[/TD]
[TD="width: 63, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] , align: right"]32[/TD]
[/TR]
</tbody>[/TABLE]


As a result in the next column cell I need the name of the highest aged person and in next column cell his age.

as in this case

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]George Paul[/TD]
[TD]85[/TD]
[/TR]
</tbody>[/TABLE]




There is around 2000 rows everyday and Presently I am doing it manually.

If I get a VBA code it would save me a lot of work.

Thanks in Advance

Jack
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What result(s) & layout would you want if John also had 85?

What do the names in a horizontal row have to do with it? Aren't you just asking who had the highest value in the table on the other sheet?

Which sheet do the results go on?
 
Last edited:
Upvote 0
Dear Peter,
Thanks for replying

First no same name will have same age as I have made the data that way.
I get the data where the persons in groups of 4 or 5 travel and they enter their names in a cell.
I use the text to column to get the names in separate columns
Then assign a leader of the group according to the highest aged person in the next column.
the result should be in the sheet where the rows are.

Like below

<!-- Please do not remove this header -->
<!-- Table easily created from Excel with ASAP Utilities (http://www.asap-utilities.com) -->
<table border="1" bordercolor="#C0C0C0" bordercolordark="#FFFFFF" cellspacing="0" align="center" frame="border">
<tr>
<td bgcolor="#FFFFFF" width="63" height="21" align="right" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" width="63" height="21" align="right" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" width="63" height="21" align="right" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" width="77" height="21" align="right" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" width="75" height="21" align="right" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" width="78" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Result</font></td>
<td bgcolor="#FFFFFF" width="63" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Result</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" width="63" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Sam</font></td>
<td bgcolor="#FFFFFF" width="63" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">John</font></td>
<td bgcolor="#FFFFFF" width="63" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Jack</font></td>
<td bgcolor="#FFFFFF" width="77" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">George Paul</font></td>
<td bgcolor="#FFFFFF" width="75" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Mathew Joy</font></td>
<td bgcolor="#FFFFFF" width="78" height="21" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">George Paul</font></td>
<td bgcolor="#FFFFFF" width="63" height="21" align="right" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">85</font></td>
</tr>
</table>

Thanks
 
Upvote 0
Thanks for the clarification. Next question is: Do you really need VBA? Could you just use formulas like this (with sheet names & ranges adjusted) copied down?

Excel Workbook
CDEFGHI
1ResultResult
2Name 6Name 2Name 5Name 8Name 7Name 762
3Name 9Name 10Name 15Name 17Name 1Name 1071
4Name 4Name 11Name 16Name 13Name 3Name 369
List


Excel Workbook
EF
1NameAge
2Name 132
3Name 258
4Name 369
5Name 445
6Name 520
7Name 619
8Name 762
9Name 850
10Name 940
11Name 1071
12Name 1133
13Name 1230
14Name 1328
15Name 1441
16Name 1518
17Name 1655
18Name 1717
19
Table
 
Upvote 0
Dear Peter,

Something is not working it is giving error #NUM !

My table is in Sheet Named KM range A2 to B804

and rows in Sheet3 B2:G2 result needed in G2 & H2

Please suggest changes in formula.

What is 15,6 in the formula and
14,6 in other formula

Jack
 
Last edited:
Upvote 0
Something is not working it is giving error #NUM !
Sounds like the numbers in KM column B are Text not actual Numbers. Hopefully new formulas below will cope with that.


and rows in Sheet3 B2:G2 result needed in G2 & H2
Bit hard to have the data and the results in the same cell so you may have to adjust the formulas a little.
Edit: Ah, hadn't seen your last post but hopefully still you can adjust if needed. :)

Excel Workbook
ABCDEFGHI
1ResultResult
2Name 6Name 2Name 5Name 8Name 7Name 762
3Name 9Name 10Name 15Name 17Name 1Name 1071
4Name 4Name 11Name 16Name 13Name 3Name 369
Sheet3




What is 15,6 in the formula and
14,6 in other formula
Have a look at the AGGREGATE Help
 
Last edited:
Upvote 0
Thanks Peter,

It is now working perfectly as desired.
Thanks your support

and thank you for this forum it really is a boon for people for me with less knowledge in excel.

Marked as Completed.
 
Upvote 0
You're very welcome. Thanks for the follow-up. :)
 
Upvote 0
Dear Peter,

I have shared the sheet to a colleague but he has office 2007. and aggregate function is not working in that office is there any other solution.

Jack
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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