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

#### dan7055

##### Active Member
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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

#### JLGWhiz

##### Well-known Member
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``````

#### Kenneth Hobson

##### Well-known Member
If you want a formula, looking in column A: =ROW(INDEX(A2:A8,MATCH(MAX(A2:A8),A2:A8),1))

#### Snakehips

##### Well-known Member
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``````

#### dan7055

##### Active Member
If you want a formula, looking in column A: =ROW(INDEX(A2:A8,MATCH(MAX(A2:A8),A2:A8),1))

Thanks, I actually need it in VBA, but I'll throw a worksheetfunction. in front of it and see if it works.

#### Kenneth Hobson

##### Well-known Member
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``

Replies
9
Views
118
Replies
2
Views
354
Replies
6
Views
203
Replies
9
Views
299
Replies
6
Views
86

1,195,743
Messages
6,011,393
Members
441,610
Latest member
Shakeable_Drip

### 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.

### Which adblocker are you using?

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

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