Two Column Lookup with a cell value falling in with a prerequisite range

你离开我真会死。 提交于 2020-01-16 07:07:04

问题


I have a list of codes, that looks like this:

RF206
RT205
RG20
etc

And I have a list of code categories that looks like this:

Prefix Range start Range end Category
RF         1          52     Investment costs
RF        53          210     Building costs
RT        1           200     Salaries
RT       201          256     Bonuses
RG        1            19     Restaurant
RG       20            30     Transport

What I would like to do is be able to match codes to categories, like this:

RF206 Building costs
RT205 Bonuses
RG20 Transport

I appreciate that a VLOOKUP can't work, as there are multiple values for every prefix (RT, RF, etc), so I can't just lookup the codes prefix. I need a way to combine looking for an exact match for the prefix and to check if the numerical part falls between the two ends of the range, to bring back the corresponding category.


回答1:


This is just a two-column-lookup (there are many examples on this site) with some LEFT and MID string function parsing thrown in.

In B2 as a standard formula,

=INDEX(Z:Z, AGGREGATE(14, 6, ROW(W$1:INDEX(W:W, MATCH("zzz",W:W )))/((W$1:INDEX(W:W, MATCH("zzz",W:W ))=LEFT(A2, 2))*(X$1:INDEX(X:X, MATCH("zzz",W:W ))<=VALUE(MID(A2, 3, 9)))), 1))

Fill down as necessary. The ranges look a little more complicated than normal because they are dynamic and do not have to be adjusted if additional entries are made (or removed).



来源:https://stackoverflow.com/questions/37157967/two-column-lookup-with-a-cell-value-falling-in-with-a-prerequisite-range

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