在数组中查找最大值的范围(位置)并存储在数组变量中?

时间:2017-06-08 20:35:11

标签: vba excel-vba excel

查看此代码的底部,我需要调用范围,范围需要是最大值的位置。有没有办法将该值的位置存储到变量中,然后将该变量用作范围?

                   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

1 个答案:

答案 0 :(得分:1)

查找范围A1:A10的最大值的位置并突出显示该值。尝试以下示例并根据您的需要进行修改,

enter image description here

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函数查找最大值的行号,并在范围内使用它。