How can I return the row number of a maximum value in a range in VBA?

dan7055

Active Member
Joined
Jul 9, 2015
Messages
312
I can use the worksheetfunction.max() to get the maximum value in a range, but how can I instead return the row number of said maximum value?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I can use the worksheetfunction.max() to get the maximum value in a range, but how can I instead return the row number of said maximum value?

Code:
myval = Application.Max(Range("A1:A10")
Range("A1:A10").Find(myVal, , xlValues).Row
 
Upvote 0
If you want a formula, looking in column A: =ROW(INDEX(A2:A8,MATCH(MAX(A2:A8),A2:A8),1))
 
Upvote 0
Maybe if range is dynamic....

Code:
Set Rng = Range("D3:D15")   'or whatever
Mx = WorksheetFunction.Max(Rng)
Rw = WorksheetFunction.Match(Mx, Rng, 0) + Rng.Row - 1
 
Upvote 0
As with any method, error catching should be done. For simplicity, it was not done in our solutions.

While one can do a formula and Evaluate it in VBA, I would just go with the Find method as #2 and #4 posts show.

Code:
MsgBox Range("A1:A10").Find(WorksheetFunction.Max(Range("A1:A10"))).Row
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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