2016-07-26 177 views
0

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

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 e.g. 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 e.g. 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 e.g. 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 

enter image description here

+5

好的,那样做。 –

+3

我想@Tom想说什么,你到底做了什么? SO的人会帮助你修复不起作用的代码,但大多数人不会为你写实际的代码 - 至少在没有签署合同的情况下。 – FreeMan

+0

我已经添加了我用于该项目的代码。我不想让任何人知道我想为我完成的想法。如果有的话,我真的很想知道如何去做。我不是一个好的程序员,对错误交流表示歉意。 – JuliusDariusBelosarius

回答

1

已经建议的公式:

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

OP表示它的某些说明将不胜感激。

MATCH

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

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

发现小于或等于lookup_value的最大值。

所以给出872.9(在I8)的794.4的“匹配”值在上述范围内的第七项(倒计时)。这是不够的(我们正在寻找大于参考值的值的第一实例),所以我们用+1降低一行(因为数据按升序排序)。所以我们现在有范围内相关行的索引(8)。这适用于:

INDEX(阵列状)

它参考的范围(这里B13:B801)和纬纱从它的第n条目的值(ROW_NUMBER从范围的顶部算起)。这里作为n = 8,这是16

对于消息框,需要比普通的16多一点,并且说明文字可以与concatenation一起添加。

OP要求Inches而不是"但对于一个消息框"似乎足够我和资本不适当的反正。

1

说我们通过I19具有I3列值。将参考值放在单元格K3中。在J3输入:

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

J4输入:

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

和复制下来。最后,在L3输入:

=MAX(J:J) 

enter image description here

(这种方法避免了阵列式)

相关问题