简体   繁体   中英

excel: lookup a range for a key, find multiple matches, return the last match

In the example below the A column contains keys and the B column contains values.

I want to search for the key "aaa", and return the last match's value: "aug".

In this case there are 3 instances of the "aaa" key, but there could be just 1 instance, or many (unknown) number of "aaa" keys. I'm always interested in just the the last match.

No additional columns can be added. The columns are not sorted.

vlookup() returns the first match ("jan") and I haven't been able to make it work in conjunction with other functions to return the last match.

Thanks.

           A     B     C    ...

        +-----+-----+
  1     | aaa | jan |
        +-----+-----+
  2     |  b  | feb |
        +-----+-----+
  3     |  c  | mar |
        +-----+-----+
  4     | aaa | apr |
        +-----+-----+
  5     |  d  | jun |
        +-----+-----+
  6     |  e  | jul |
        +-----+-----+
  7     | aaa | aug |
        +-----+-----+
  8     |  f  | sep |
        +-----+-----+
  9     |  g  | oct |
        +-----+-----+

=LOOKUP(1,0/(A1:A9="aaa"),B1:B9)

问候

Please write the array formula below.

=index(B1:B9, max(if(a1:a9="aaa", row(a1:a9))))

then press ctrl + shift + enter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM