Match Backwards

G

Guest

I need a function like match that gives the last occurrence of a match rather
than the first. For example, if the data in a column is:
1
2
3
4
1
2
3
4
1
2
3
4
then MATCH(2,A1:A12,0) gives 2 (the second row). I need
LASTMATCH(2,A1:A12,0) to give 10 ( the last row containing 2).

Thanks in advance for your help.
 
G

Guest

I tried it. It gave me 6 (the second occurence) rather than 10 (the last
occurence)

We are moving in the right direction, however. Thanks for your fast response.
 
D

Domenic

Try...

=MATCH(2,1/(A1:A12=2))

....confirmed with CONTROL+SHIFT+ENTER, not just ENTER.

OR

=LOOKUP(2,1/(A1:A12=2),ROW(A1:A12)-ROW(A1)+1)

....confirmed with just ENTER.

Note that if you're looking for the last occurrence of 4, change '=2' to
'=4'.

Hope this helps!
 
D

Don Guillett

Actually this ARRAY formula will do it . Array formulas must be
entered/edited with ctrl+shift+enter

=MAX(IF(a1:a13=2,ROW(a1:a13)))
 
G

Guest

Thank you both very much. This saves me much time that I used to spend
inverting the array just to find the last occurence!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top