简体   繁体   English

根据条件从范围中选择一个单元格值

[英]Select a cell value from a range based on criteria

I'm trying to figure out a sleeker method for determining the value of a cell based on criteria defined in a given range. 我试图找出一种更巧妙的方法,用于根据给定范围内定义的标准确定单元格的值。 To put it bluntly, I have a column for standard viscosity, standard temperature, and measured temperature. 坦率地说,我有一列标准粘度,标准温度和测量温度。 I'm needing to create a fourth column that will select the standard viscosity based on the measured temperature. 我需要创建第四列,该列将根据测量的温度选择标准粘度。 For example, if measured temperature is greater than or equal to 0 o C and less than 1 o C: return standard viscosity for 0 o C. 例如,如果测得的温度是大于或等于0℃且小于1个O C:返回标准粘度为0℃。

My issue is that I have a large range and find it to tedious to create a custom expression for each range. 我的问题是我有很大的范围,发现为每个范围创建自定义表达式很繁琐。 I've created a nightmarish function that was composed of IF(AND()) statements but find this exhausting, especially if I try to create an expression for a 0-200 o C scale in single digit increments. 我创建了一个由IF(AND())语句组成的噩梦函数,但是发现这很累人,尤其是当我尝试为0-200 o C标度创建一个单位增量的表达式时。

Here is a sample of a code that works but is quite cumbersome: 这是一个有效但很麻烦的代码示例:

=IF(AND(G8>=$C$7,G8<$C$8),$D$7,0)+IF(AND(G8>=$C$8,G8<$C$9),$D$8,0)+....

or 要么

=IF(AND(measured temp>=0,measured temp<1),$D$7,0)+IF(AND(measured temp>=1,measured temp<2),$D$8,0)

How could I approach this in a sleeker manner? 我该如何更时尚地处理呢?

You can achieve this by the VLOOKUP function. 您可以通过VLOOKUP函数来实现。

=VLOOKUP(G8;$C$7:$D$...;2;TRUE)

Replace the three dots with the index of the last row of your table. 用表的最后一行的索引替换三个点。

The first argument of VLOOKUP is the value to search for; VLOOKUP的第一个参数是要搜索的值; the second argument is the range whose first column is to be searched for the value; 第二个参数是要在其第一列中搜索值的范围; the third argument is the index of the column containing the values to return (within the range, so 2 means the second column within the range, which is D in your case); 第三个参数是包含要返回的值的列的索引(在范围内,因此2表示范围内的第二列,在您的情况下为D); TRUE means that you do not want to search for an exact match, but that the column to be search is an ordered list of values defining intervals. TRUE表示您不希望搜索精确匹配,而是要搜索的列是定义间隔的值的有序列表。

Edit: 编辑:

With MATCH and OFFSET (guessed, not tried), if column with result values is left relative to column of criterion values: 对于MATCH和OFFSET(猜测,未尝试),如果相对于标准值的列保留了带有结果值的列:

=OFFSET($C$7;...;MATCH(G8;$C$7:$C$...;1) - 1)

Replace the first three dots with the position of the result column, relative to column C (so 1 if it's column D, and -1 if it's column B), and the second three dots with the index of the last row of your range, as above. 将结果的前三个点替换为相对于C列的结果列的位置(如果是D列则为1,如果是B列则为-1),将后三个点替换为范围的最后一行的索引,如上。

Edit2: EDIT2:

INDEX instead of OFFSET is even better, se pnuts's answer and the comment below: 以下是INDEX的答案和评论:INDEX而不是OFFSET更好。

=INDEX($D7:$D...;MATCH(G8;$C$7:$C$...;1))

如果您在F2中说出测得的温度并且您的数据表是A:C,请尝试:

=INDEX(A:A,MATCH(F2,C:C))  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM