Default VBA to find the maximum value against a single criteria

tuanbuffalo

New Member
Joined
Mar 16, 2018
Messages
1
I need to find the maximum value present in column AC against multiple instances of variable X in column D, and populate the value in column F.

For example (apologies, I cannot share a true dataset due to the confidential nature of the data):

[TABLE="class: cms_table_grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]Column D[/TD]
[TD]...[/TD]
[TD]Column F[/TD]
[TD]...[/TD]
[TD]Column AC[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ID[/TD]
[TD]...[/TD]
[TD]MaxSeverity[/TD]
[TD]...[/TD]
[TD]Severity[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]A[/TD]
[TD]...[/TD]
[TD]50[/TD]
[TD]...[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]A[/TD]
[TD]...[/TD]
[TD]50[/TD]
[TD]...[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]B[/TD]
[TD]...[/TD]
[TD]30[/TD]
[TD]...[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]C[/TD]
[TD]...[/TD]
[TD]30[/TD]
[TD]...[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]A[/TD]
[TD]...[/TD]
[TD]50[/TD]
[TD]...[/TD]
[TD]40[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]B[/TD]
[TD]...[/TD]
[TD]30[/TD]
[TD]...[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]B[/TD]
[TD]...[/TD]
[TD]30[/TD]
[TD]...[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]C[/TD]
[TD]...[/TD]
[TD]30[/TD]
[TD]...[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]D[/TD]
[TD]...[/TD]
[TD]50[/TD]
[TD]...[/TD]
[TD]50[/TD]
[/TR]
</tbody>[/TABLE]



I've got a solution which uses nested CountIfs, but it takes around 45s on a dataset of 10k rows and is, well, inelegant to say the least.

Any suggestions from the community?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I'm not sure why you would need VBA or nested COUNTIFs.

In Column F:
=MAX(IF($D$2:$D$10000=D2,$AC$2:$AC$10000))

Confirm with CTRL-SHIFT-ENTER rather than just Enter.
Copy Down.


Excel 2010
DEFGHIJKLMNOPQRSTUVWXYZAAABAC
1ID...MaxSeverity...Severity
2A...50...10
3A...50...50
4B...30...20
5C...30...30
6A...50...40
7B...30...30
8B...30...30
9C...30...30
10D...50...50
Sheet1
Cell Formulas
RangeFormula
F2{=MAX(IF($D$2:$D$10000=D2,$AC$2:$AC$10000))}
F3{=MAX(IF($D$2:$D$10000=D3,$AC$2:$AC$10000))}
F4{=MAX(IF($D$2:$D$10000=D4,$AC$2:$AC$10000))}
F5{=MAX(IF($D$2:$D$10000=D5,$AC$2:$AC$10000))}
F6{=MAX(IF($D$2:$D$10000=D6,$AC$2:$AC$10000))}
F7{=MAX(IF($D$2:$D$10000=D7,$AC$2:$AC$10000))}
F8{=MAX(IF($D$2:$D$10000=D8,$AC$2:$AC$10000))}
F9{=MAX(IF($D$2:$D$10000=D9,$AC$2:$AC$10000))}
F10{=MAX(IF($D$2:$D$10000=D10,$AC$2:$AC$10000))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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