Multicolumn lookup

半城伤御伤魂 提交于 2020-02-08 10:04:49

问题


There are a lot of posts that relate, but I haven't found one quite like this. I am currently going through excel to help out in speeding up a process a little more. The excel file has two spreadsheets. One is data the second is the summary. On the data spreadsheet, I have the first column as names, and the next 7 columns with data values (Not all filled).

Name     Data1    Data2    Data3   Country    Address
VA       123      456      621     USA        ExampleSt.
MD                123              France     123Street
DC       621                       Korea      999Avenue

UseCol   Value
Data2    456
Data3    621
Data1    000

My question is, I am given the value "621" (which can appear in multiple columns, but won't appear in ). I am given which set it should be in "data1, data2, data3...". How would I go about finding the name with that information? No VBA, only through excel.

I got stopped here with this code.

=INDEX(A1:D4,MATCH('621',*What do I put here*,0)

For that middle section, the reason why it is a problem is because I'm given which data column to use in another spreadsheet.

EDIT

So, I have followed what Tim Williams has said about using the offset. However, now I have a second column I am trying to get to. So the code that I used to get the Name is as follows

 =IFERROR(INDEX(A2:A4,MATCH(B7,OFFSET(A2:A4,0,MATCH(A7,B1:D1,0)),0,1),"ERROR")

What changes do I have to make to the OFFSET portion to now look for the Country, or the Address cell? I believe the only part I need to change is that inner "MATCH" function. Should I do MATCH(A7,B1:D1,0)+3 to get to Country column? Thank you.


回答1:


This worked for me as long as each number can only appear once per column.

EDIT: for getting the matching value from other columns you only need to adjust the first part of the formula.




回答2:


The parameter you are missing is your lookup range in which you are trying to find the row that contains 621. Simply reference the desired column range, or create a named range and reference that.

WITH A GIVEN RANGE

I created a named range for the NAME column called "NAMERANGE".
I created a named range for the DATA1 column called "DATA1RANGE".

Using this formula I can retrieve the name if any of the row containing the given value in the given column range:

=INDEX(NAMERANGE,MATCH(621,DATA1RANGE,0))

Replace the value, and Data Range as needed.

WITH A DYNAMIC RANGE

If you need to dynamically choose the data range, you can use the INDIRECT() function to generate a reference to your desired lookup column. For example, in R1C1 style references, to get the DATA3 column, you would use the following formula:

=INDIRECT("C"&4&")

So in R1C1 style, given that you want to search in the 2nd data column (which is the third column of the spreadsheet), your formula could be:

=INDEX(NAMERANGE,MATCH(621,INDIRECT("C"&3),0))



来源:https://stackoverflow.com/questions/33025568/multicolumn-lookup

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