查看此代码的底部,我需要调用范围,范围需要是最大值的位置。有没有办法将该值的位置存储到变量中,然后将该变量用作范围?
Dim Retest As Boolean
If (Abs(Suspect - mean) / SD) > LowConf Then
MsgBox "95% outlier: " & Suspect
Retest = True
End If
If (Abs(Suspect - mean) / SD) > HighConf Then
MsgBox "99% outlier: " & Suspect
Retest = True
End If
If Retest = True And Suspect = Application.WorksheetFunction.Max(DataSet) Then
Range(?).Delete Shift:=xlUp
End If
答案 0 :(得分:1)
查找范围A1:A10
的最大值的位置并突出显示该值。尝试以下示例并根据您的需要进行修改,
Sub find()
Dim i As Long, rownum As Integer
' variable i contains the max value of range A1:A10
i = Application.WorksheetFunction.Max(Range("A1:A10"))
' rownum is the row number of the maximum value
rownum = Application.WorksheetFunction.Match(i, Range("A1:A10"), 0)
' use the rownum and highlight the cell
Range("A" & rownum).Interior.Color = vbGreen
End Sub
此vba代码使用match
函数查找最大值的行号,并在范围内使用它。