Excel查找大于参考值的第一个实例

快速的问题。 我正在尝试创build一个程序,该程序查找比I8中的最大容量大的值的第一个实例。 我想比较I13:I80中Vol列的体积与I8中的最大体积。 然后,我希望excel将列B13:B80中的相应带子作为消息框输出。 因此,在这种情况下,会输出一个消息框,指出“墙的高度为16英寸”。因为B20是与大于最大值的第一个体积对应的带的值。

Public Sub dimensionInput() Dim wallWidth As Double 'Get Wall Width Input wallWidth = Application.InputBox("Input Desired Secondary Containment Wall Width in Inches", "Wall Width", 1) If wallWidth = False Then Call zeroFill Exit Sub Else Application.Worksheets("Sheet1").Range("D3").Value = wallWidth End If Dim wallLen As Variant 'Get Wall Length Input wallLen = Application.InputBox("Input Desired Secondary Containment Wall Width in Inches", "Wall Width", 1) If wallLen = False Then Call zeroFill Exit Sub Else Application.Worksheets("Sheet1").Range("E3").Value = wallLen End If Dim arrayDia() As String Dim diameter As Variant 'Get Diameter Input diameter = Application.InputBox("Input Tank(s) Diameter Seperated by a Comma and Space eg N1, N2, N3, ...", "Diameter", 1) arrayDia() = Split(diameter, ",") For i = LBound(arrayDia) To UBound(arrayDia) Cells(6, i + 3).Value = arrayDia(i) Next i Dim arrayLen() As String Dim length As Variant 'Get Lenth Input length = Application.InputBox("Input Desired Length Seperated by a Comma and Space eg N1, N2, N3, ...", "Length", 1) arrayLen() = Split(length, ",") For i = LBound(arrayLen) To UBound(arrayLen) Cells(7, i + 3).Value = arrayLen(i) Next i 'Dim arrayOrient() As String 'Dim orient As Variant 'Get Orient Input 'orient = Application.InputBox("Input Desired Orient", "Orient", H) 'arrayOrient() = Split(orient, ",") 'For i = LBound(arrayOrient) To UBound(arrayOrient) ' Cells(9, i + 3).Value = arrayOrient(i) 'Next i Dim arrayOffset() As String Dim offset As Variant 'Get Offset Input offset = Application.InputBox("Input Desired Offset Seperated by a Comma and Space eg N1, N2, N3, ...", "Offset", 0) arrayOffset() = Split(offset, ",") For i = LBound(arrayOffset) To UBound(arrayOffset) Cells(10, i + 3).Value = arrayOffset(i) Next i End Sub Public Sub zeroFill() Application.Worksheets("Sheet1").Range("C6:H7").Value = "0" 'Application.Worksheets("Sheet1").Range("C9:H9").Value = "H" Application.Worksheets("Sheet1").Range("C10:H10").Value = "0" End Sub 

在这里输入图像说明

build议的公式如下:

 ="The height of the wall is"&INDEX(B13:B80,MATCH(I8,I13:I80,1)+1)&"""" 

OP表示将赞赏一些解释。

比赛

在范围I13:I80查找相关值( I8 )。 由于单个单元格需要结果(不涉及公式拖动),所以锚定( $用于修复引用)不是必需的。

第三个参数(这里是1 )每M $:

find小于或等于lookup_value的最大值。

因此,给定872.9 (在I8),“匹配”值794.4是该范围中的第七项(倒数)。 这是不够的(我们正在寻找比引用大的值的第一实例 ),所以我们下一行(因为数据是按升序sorting) +1 。 所以我们现在有相关行的索引(8)在范围内。 这适用于:

INDEX (数组forms)

它考虑一个范围(这里是B13:B801 ),并从中选取第n个条目的值(从该范围的顶部开始计数的row_number)。 这里n = 8这是16

对于消息框,需要比普通16一点,并且说明文本可以连接添加。

OP要求Inches而不是"但是对于一个消息框"似乎对我来说是足够的,大小写不适当。

假设我们从I3I19在第一列中都有价值观。 将参考值放在单元格K3中 。 在J3中input:

 =IF(I3>$K$3,I3,"") 

J4中input:

 =IF(AND(I4>$K$3,COUNT($J$3:$J3)=0),I4,"") 

并抄下来。 最后在L3input:

 =MAX(J:J) 

在这里输入图像说明

(这个方法避免了数组公式)