如何在AutoFiltered范围内find最小值?

我有一个列有两个值范围,特别是0-30000和60000+,我需要从60000范围内提取最小的两个值。

到目前为止唯一的方法是使用AutoFilter来生成要提取的所需数据的子集。 我的问题是,自动筛选function不会返回一个范围的引用。 如果是这样,我可以使用SMALL函数来获取我正在寻找的值。

我怎样才能从这个过滤的数据中筛选和提取两个最小的值?

我放弃了使用Autofilter的想法。 相反,我使用了SMALL和一个循环的组合。

 Cells(2, secIdCol).Select Set valsRange = Range(Selection, Selection.End(xlDown)) For Each val In valsRange If val.Value < 599999 Then val.Value = "" // I don't save changes val1 = Application.WorksheetFunction.Small(valsRange, 1) val2 = Application.WorksheetFunction.Small(valsRange, 2) End If Next val 

我不认为你一定需要VBA。 你有没有考虑过使用ctrl + shiftinput的数组公式:

  =MIN(IF(A1:A7>2999,A1:A7)) 

这里有一个不使用SMALL工作表函数的方法:

 With Worksheets("Sheet1") Dim lastRow As Long lastRow = .Cells(2, secIdCol).CurrentRegion.Rows.Count + 1 Dim rowIndex As Long Dim currentValue As Long Dim val1 As Long Dim val2 As Long ' Set val1 to maximum possible long value val1 = 2147483647 For rowIndex = 2 To lastRow currentValue = CLng(.Cells(rowIndex, secIdCol).Value) If (currentValue > 59999) Then If (currentValue < val1) Then val2 = val1 val1 = currentValue End If End If Next rowIndex End With MsgBox val1 & " | " & val2