VBA code to get highest hours value for all duplicate numbers, pls check below table

ashish_RC

New Member
Joined
Sep 9, 2018
Messages
3
[TABLE="width: 311"]
<colgroup><col span="3"><col></colgroup><tbody>[TR]
[TD]NUMBER[/TD]
[TD]NAME[/TD]
[TD]HOURS[/TD]
[TD]HIGHEST HOURS[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]23[/TD]
[TD]54[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]43[/TD]
[TD]66[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]66[/TD]
[TD]66[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]22[/TD]
[TD]54[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]53[/TD]
[TD]66[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]23[/TD]
[TD]66[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]54[/TD]
[TD]54[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]65[/TD]
[TD]66[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]22[/TD]
[TD]54[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to the MrExcel board!

Do you really need a macro? Could you use one of these formulas, copied down?

Excel Workbook
ABCDE
1NUMBERNAMEHOURSHIGHEST HOURS
29999XXXX235454
36577XXXX436666
46577XXXX666666
59999XXXX225454
66577XXXX536666
76577XXXX236666
89999XXXX545454
96577XXXX656666
109999XXXX225454
Highest Hours
 
Upvote 0
Welcome to the MrExcel board!

Do you really need a macro? Could you use one of these formulas, copied down?

Highest Hours

ABCDE
NAME
XXXX
XXXX
XXXX
XXXX
XXXX
XXXX
XXXX
XXXX
XXXX

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:75px;"><col style="width:57px;"><col style="width:65px;"><col style="width:127px;"><col style="width:43px;"></colgroup><tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]1[/TD]
[TD="align: right"]NUMBER[/TD]

[TD="align: right"]HOURS[/TD]
[TD="align: right"]HIGHEST HOURS[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]2[/TD]
[TD="align: right"]9999[/TD]

[TD="align: right"]23[/TD]
[TD="align: right"]54[/TD]
[TD="align: right"]54[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]3[/TD]
[TD="align: right"]6577[/TD]

[TD="align: right"]43[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]4[/TD]
[TD="align: right"]6577[/TD]

[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]5[/TD]
[TD="align: right"]9999[/TD]

[TD="align: right"]22[/TD]
[TD="align: right"]54[/TD]
[TD="align: right"]54[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]6[/TD]
[TD="align: right"]6577[/TD]

[TD="align: right"]53[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]7[/TD]
[TD="align: right"]6577[/TD]

[TD="align: right"]23[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]8[/TD]
[TD="align: right"]9999[/TD]

[TD="align: right"]54[/TD]
[TD="align: right"]54[/TD]
[TD="align: right"]54[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]9[/TD]
[TD="align: right"]6577[/TD]

[TD="align: right"]65[/TD]
[TD="align: right"]66[/TD]
[TD="align: right"]66[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]10[/TD]
[TD="align: right"]9999[/TD]

[TD="align: right"]22[/TD]
[TD="align: right"]54[/TD]
[TD="align: right"]54[/TD]

</tbody>

Spreadsheet Formulas
CellFormula
D2=MAXIFS(C$2:C$10,A$2:A$10,A2)
E2=AGGREGATE(14,6,C$2:C$10/(A$2:A$10=A2),1)

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Thank you Peter. This solution also helpful for me.

I need to calculate sum of hours where numbers are duplicate and paste the total result in TOTAL HOURS column.

Can I get below result using excel formula?

[TABLE="width: 311"]
<colgroup><col span="3"><col></colgroup><tbody>[TR]
[TD]NUMBER[/TD]
[TD]NAME[/TD]
[TD]HOURS[/TD]
[TD]TOTAL HOURS[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]5[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]10[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]10[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]5[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]10[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]10[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]5[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]6577[/TD]
[TD]XXXX[/TD]
[TD]10[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]9999[/TD]
[TD]XXXX[/TD]
[TD]5[/TD]
[TD]20[/TD]
[/TR]
</tbody>[/TABLE]


Regards
Ashish
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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