简体   繁体   中英

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:

Excel示例

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.

Then I want to be able to duplicate this formula on all column C.

I have this formula that I use in column C starting from C2:

=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.

Use another column for the result, not column C , to avoid a circular reference in the formula. 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:

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:

C2:
=IFERROR(VLOOKUP(B2, A:E, 5, 0), "")

I would use INDEX MATCH it is more efficient. 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)),"")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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