Excel Find column value in another column and return value next to it

人盡茶涼 提交于 2019-12-25 07:17:37

问题


I want to do some manipulation with data in Excel. As a background, I have 2 tables in different sheets with inventory, one is for the material needed to construct a device and the other with the material in stock, both of them have the same components but are sorted different. I want to combine them as follows: The table with the material required needs to know the stock value to verify how many are needed and in that case order them.

For example:

TABLE 1 SHEET 1

Part #    Needed    Stock
1234      5         I want here the value from table 2
5678      5         I want here the value from table 2
9876      6         I want here the value from table 2
5432      7         I want here the value from table 2

TABLE 2 SHEET 2

Part #    Stock
5432      2
9876      4
1234      1
5678      4

The point is not checking one by one part number manually in order to put the stock number from table 2 in the stock column from table 1.

I will be very thankful if you could help me.


回答1:


You can use the INDEX-MATCH functions to pull this off. For the Stock column in your example you can use the following as the function in row 2 of the stock column

=INDEX(Sheet2!B$2:B$5,MATCH(Sheet1!A2,Sheet2!A$2:A$5,0))

You can then copy the formula and copy down for all rows needed. The $ signs will keep your return value range and lookup value range stable as you copy the formula into other rows. The lookup value will change for each subsequent row.

Here are some notes in order to describe what is happening here.

=INDEX(Return_value_range, MATCH(Lookup_value, Lookup_value_range, Match_type))
Return_value_range – The range that holds the return values
Lookup_value – The value you want to find in the lookup value array
Lookup_value_range – The range containing lookup values
Match_type – Exact (0), Nearest Greater Than (-1), or Nearest Less Than (1)

Lastly here is a link that gives a could description of using the INDEX-MATCH versus a the previously very common VLOOKUP function http://eimagine.com/say-goodbye-to-vlookup-and-hello-to-index-match/



来源:https://stackoverflow.com/questions/39834282/excel-find-column-value-in-another-column-and-return-value-next-to-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!