我试图找到某个范围内的最大值,并获取出现该最大值的行的行号
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
答案 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