worksheetfunction max with multiple criteria in excel VBA

rarmn

New Member
Joined
Apr 30, 2013
Messages
20
I would like to use worksheetfunction max with multiple criteria in excel VBA. I have the following data:

Col ACol B
a1
a2
a3
b4
b5

<colgroup><col width="44"><col width="44"></colgroup> <tbody>
</tbody>

In excel i was able to use the formula =MAX(($A$2:$A$6=$A2)*($B$2:$B$6)). I would like to be able to do the same in VBA using the worksheetfunction.max. I was trying something like

worksheetfunction.MAX(($A$2:$A$6=$A2)*($B$2:$B$6)) and it didnt work. Any suggestions on these line on how to proceed?

Thanks.


<colgroup><col width="44"><col width="44"></colgroup> <tbody>
</tbody>



<colgroup><col width="86"><col width="86"></colgroup> <tbody>
</tbody>
 
Code:
Dim i as integer
Dim rowmax as integer

rowmax = 10 'enter whatever value or expression here that you want

For i = 2 to rowmax

Range("C" & i).FormulaArray = "=MAX(($A$2:$A$6=$A$" & i & ")*($B$2:$B$6))"

Next i

Try the above, but make sure you define your rowmax variable however you want it.

This code works great and it will help me proceed further with my other requirements. Thanks
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,639
Messages
6,125,970
Members
449,276
Latest member
surendra75

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