在条件下找到最接近当前单元格的单元格 [英] finding the cell that is closest to the current cell with conditions
问题描述
我有一行值 - 1,2,3,8,35,7,8,3,5,7,x
X是我想要的公式在哪里
X is where I want the formula to be
我想以某种方式获取8的值最接近对于X(在这种情况下不是第4行,而是第7行)
I'd like to somehow get the value of the row which 8 is the closest to X (so not row 4 in this case, but row 7)
如果我使用 match(8,A:A,0 )
我得到了它找到的第一个匹配。
If I use match("8",A:A,0)
I get the first match it finds.
如何找到与计算发生的单元格最接近的匹配?
How do I find the closest match to the cell where the calculation occurs?
推荐答案
您可以使用:
{=MATCH(2,1/(A1:A10=8))}
只要记住它是数组函数,所以必须使用CTRL + SHIFT + ENTER
just remember it is an array function, so CTRL+SHIFT+ENTER must be used
答案是基于MATCH函数的技巧和行为。我将允许我从 ozgrid 复制说明:
The answer is based on a trick and behaviour of the MATCH function. I will allow myself to copy the explanation from ozgrid:
这里的魔法实际上在MATCH函数中比数组多。在这里使用匹配函数的两个有趣的属性:
The magic here is actually in the MATCH function more than the array. Two interesting properties of the match function are being used here:
1)使用MATCH,如果找不到匹配,则函数将返回最后一个值的位置数组,所以如果你做了= MATCH(8,{1,2,3,4,5,6,7,6,5,4,3,2,1}),你的结果是= 13,因为有没有8在数组中找到
1) With MATCH, if no match is found, then the function will return the position of the last value in the array, so if you did =MATCH(8,{1,2,3,4,5,6,7,6,5,4,3,2,1}), your result is = 13, since there was no 8 to find in the array
2)MATCH将返回最后一个值的位置,但不会返回错误的位置(或空值) ),所以如果你有= MATCH(8,{1,2,3,4,#DIV / 0!,#DIV / 0!,7,6,5,4,3,#DIV / 0!,#DIV / 0!}),你的结果是= 11,因为第11位的3是数组中的最后一个值
2) MATCH will return the position of the last value, but won't return the position of an error (or of a blank value), so if you have =MATCH(8,{1,2,3,4,#DIV/0!,#DIV/0!,7,6,5,4,3,#DIV/0!,#DIV/0!}), your result is = 11, as the 3 in the 11th position is the last value in the array
所以daddylonglegs的公式检查每个单元格对目标值与数组公式中的(A1:A13 = B1),为单元格匹配的位置给出一个带有TRUE(或1)的数组,其余的为FALSE(或0)。将1分为1,无论数组为TRUE,并且#DIV / 0!无论哪个阵列都是假的。所以他的公式被评估为
So daddylonglegs' formula checks each cell against the target value with (A1:A13=B1) in the array formula, giving an array with TRUE (or 1) for the positions where the cells match, and with FALSE (or 0) for the rest. Dividing 1 by this results in 1s wherever that array was TRUE, and #DIV/0! wherever that array was false. So his formula is evaluated as
= MATCH(2,{#DIV / 0!,1,#DIV / 0!,#DIV / 0!,#DIV / 0,#DIV / 0!,1,#DIV / 0!,1,#DIV / 0!,#DIV / 0!,#DIV / 0!,#DIV / 0!})
=MATCH(2,{#DIV/0!,1,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!,1,#DIV/0!,1,#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!})
由于在数组中没有找到'2',而在第9个位置找到最后一个值(1),所以MATCH返回9
Since no '2' is found in the array, and the last value (1) is found in the 9th position, the MATCH returns 9
这篇关于在条件下找到最接近当前单元格的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!