问题
I have a list of names and numbers
NAME | Number
Joe | 1
Jane | 0
Jack | 1
Jill | 0
John | 1
I'm trying to look up the numbers and find out the corresponding name The formula I have is
{=index($A$2:$B$6, SMALL(IF($B$2:$B$6 = 1, ROW ($B$2:$B$6)), Row(1:1)), 1)}
As I understand the formula:
- First Excel runs the index function. It runs the index function on the array A2 through B6.
- For the row number in the index function, it uses the function
SMALL(IF($B$2:$B$6 = 1, ROW ($B$2:$B$6)), Row(1:1)
. This examines an array, b2:b6, and if the element under consideration in B2:B6 is a 1, it returns the row number of b2:b6. In this case, it would return a 2. - At this point I'm kind of stuck. I'm guessing that the second ROW function returns first case of the 1 derived from the small function
- Lastly, the index function finds the name located in column 1 for the index found.
回答1:
Your understanding of this formula is pretty good. I assume that you are going to copy it down enough rows to get all the values reported? If so, here is what is happening:
INDEX
needs to know what row to go retrieve. In order to do this, we are going to give it a row number.- In order to get a row number we need to know which items meet the condition. We use the
IF
conditional to report a row number if the condition is met (otherwise we getFALSE
). - Since that will give us an array of row numbers, we then use the
SMALL
function to give us a single value. That satisfies theINDEX
function which needs a single row to retrieve. - So which value do we choose from
SMALL
? Well, we just give it a sequence of 1-2-3-... by usingROW(1:1)
. When this is copied down, it will becomeROW(2:2)
,ROW(3:3)
, etc. Each of these will return 1, 2, 3, respectively so we get the next entry. Note thatSMALL
skipsFALSE
so it works for the output of theIF
call.
So the first call to ROW
(inside the IF
) is used to determine the row of the values in the array that match the condition.
The second call to ROW(1:1)
is just used to get an incrementing sequence once the formula is copied down.
The final thing to note is that your formula will be off by one row on the answers because ROW($B$2:$B$6)
will return the absolute row number of those rows and not one that is relative to the starting corner of the array of interest. In this case, you will need to subtract 1 to get it to work (since it starts in row 2). In the general case, use a formula like this which accounts for the offset of the array:
=INDEX($A$2:$A$6,SMALL(IF($B$2:$B$6=1,ROW($B$2:$B$6)-ROW($B$2)+1),ROW(1:1)))
That is an array formula like you have (enter with CTRL+SHIFT+ENTER). The corresponding ranges look like:

来源:https://stackoverflow.com/questions/30222635/lookup-multiple-items