return values from multiple matching rows

前端 未结 3 1226
野的像风
野的像风 2020-12-10 21:48

First off, I\'d like to do this without VB if possible, so I don\'t have to go through the hassle of teaching recipients how to enable macros.

Now, I believ

3条回答
  •  佛祖请我去吃肉
    2020-12-10 22:28

    OK I figured out a way to get my desired results. It isn't the cleanest or best way, but it achieves my goal of listing the results horizontally, and avoids macros or pivot tables.

    I use a hidden worksheet to list out all the pos and sts values, concatenated as a single value. So...

    sts   | pos   | bye
    ----------------------
    2     | QB    | 8
    2     | RB    | 5
    2     | QB    | 11
    0     | WR    | 7
    . . .
    

    ...becomes....

         D   | E
        -----------
    5  | 2QB | 8
    6  | 2RB | 5
    7  | 2QB | 11
    8  | 0WR | 7
         . . .
    

    Then, I have a "shadow" results area that mimics the results area on my front-page worksheet. It looks like so:

         G   | H   | I   | J   | K
        -----------------------------
    5  | QB  |     |     |     |     |
    6  | RB  |     |     |     |     |
    7  | WR  |     |     |     |     | . . .
    

    In H5:H7, I have the following formula:

    =IFERROR((ADDRESS(MATCH("2"&$G5,$D$5:$D$305,0)+4,COLUMN($E5),4)),"")
    

    This returns the first cell reference it finds in the concatenated column that starts with 2 and ends with the value in column G (e.g. the formulas in row 5 are looking for "2QB").

    Then, in I5:n7 I have the following modified formula:

    =IFERROR(ADDRESS(MATCH("2"&$G5,INDIRECT(ADDRESS(ROW(INDIRECT(H5))+1,4)&":$d$"&MAX(305,ROW(INDIRECT(H5))+1)),0)+ROW(INDIRECT(H5)),COLUMN($E5),4),"")
    

    The reason I modify the subsequent columns is to change the range in which the formula is looking for its value to start at the next row after the previously found value. For example, with the data above, the formula in H5 would look for "2QB" in D5:D*n*, and return the first row it finds and attach it to column E, which would be E5.

    The formula in I5 would then look for "2QB" starting in D*6* instead of D5, a row after the row referenced in H5's result.

    Hopefully that made sense.

    So what I end up with in my hidden worksheet is this:

         G   | H   | I   | J   | K
        -----------------------------
    5  | QB  | E5  | E7  |     |     |
    6  | RB  | E6  |     |     |     |
    7  | WR  |     |     |     |     | . . .
    

    Then, on my front page worksheet, I simply get the values (the bye) referenced by the cells in H5:*n*7 using:

    =IFERROR(INDIRECT(lookups!H5),"")
    

    ...which gives me my final result:

         G   | H   | I   | J   | K
        -----------------------------
    5  | QB  | 8   | 11  |     |     |
    6  | RB  | 5   |     |     |     |
    7  | WR  |     |     |     |     | . . .
    

    Like I said, it's totally convoluted, but it works, and I can always refine it later if I figure out how. :) Thanks to you who took a swing at this seemingly complex problem for me! I'm sure your answers work beautifully as well.

提交回复
热议问题