[英]Formula to check if the value of a cell in a column is in the range of a cell in another column and add a value on the same line
I want to find a formula to check if the value of a cell in a column is in the range of a cell in another column and then add a value comprised of another column on the same line of the matching cell you are looking for in the range, and then to be able to duplicate this formula to all the cells in the column you are testing. 我想找到一个公式来检查一列中某个单元格的值是否在另一列中某个单元格的范围内,然后在要查找的匹配单元格的同一行上添加一个包含另一列的值范围,然后能够将此公式复制到要测试的列中的所有单元格。
An example: 一个例子:
In this pic, I want to test if the values in column B match values from column A, when it does I want the formula to check the value on the same line of column A but on column E and add it to C column on the same line as column BI am testing. 在此图片中,我想测试B列中的值是否匹配A列中的值,当我希望公式检查A列的同一行但E列中的值并将其添加到C列时与列BI am测试相同。
Then I want to be able to duplicate this formula on all column C. 然后,我希望能够在所有列C上重复此公式。
I have this formula that I use in column C starting from C2: 我有从C2开始在C列中使用的这个公式:
=IF(COUNTIF(A2:A5,B2),E2,0)
But it does not work well and if I try to duplicate if the range changes to A3:A6, etc. 但是它不能很好地工作,并且如果范围更改为A3:A6等,如果我尝试复制,请执行以下操作。
Use another column for the result, not column C
, to avoid a circular reference in the formula. 为结果使用另一列而不是
C
列,以避免在公式中使用循环引用。 For example you can use column D
or F
If you choose column D
you can use this formula in cell D2
and autofill column D with it: 例如,您可以使用
D
列或F
列。如果选择D
列,则可以在单元格D2
使用此公式,并使用它自动填充D列:
D2:
=C2 + IFERROR(VLOOKUP(B2, A:E, 5, 0), 0)
As per you last comment, if you want only the matched value on column E
otherwise stay blank, you can have it in column C
but use: 根据您的最后评论,如果只希望
E
列上的匹配值不为空,则可以在C
列中使用它,但使用:
C2:
=IFERROR(VLOOKUP(B2, A:E, 5, 0), "")
I would use INDEX MATCH it is more efficient. 我会使用INDEX MATCH来提高效率。 And from the example it seams like you want to concatenate add one string to another not add numbers if that is the case I would do the following
从示例中可以看出,您希望将一个字符串添加到另一个字符串中而不是添加数字,如果是这种情况,我将执行以下操作
=IFERROR(C2&INDEX($E:$E,MATCH($A:$A,$B2,0)),"")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.