行数是范围内的最大值

时间:2017-11-28 14:19:08

标签: excel vba excel-vba

我试图找到某个范围内的最大值,并获取出现该最大值的行的行号

Sub MaximumValue()

Dim MaxVal As Double
Dim Row As Long

Set Workrange = Selection
MaxVal = Application.Max(Workrange)
Range(MaxVal).Select
Row = ActiveCell.Row

MsgBox "MaxValue is in Row" & Row

End Sub

1 个答案:

答案 0 :(得分:1)

您需要使用Find功能在MaxVal中查找Workrange

<强>代码

Option Explicit

Sub MaximumValue()

Dim MaxVal As Double
Dim Workrange As Range, FndRng As Range
Dim lRow As Long

Set Workrange = Selection
MaxVal = Application.Max(Workrange)

Set FndRng = Workrange.Find(what:=MaxVal)
lRow = FndRng.Row

MsgBox "MaxValue is in Row " & lRow

End Sub