find the last Occurrence in a table and return the value on the cell above it

linkn00

New Member
Joined
Aug 15, 2019
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am struggling to figure out how to find the last Occurrence in a table and return the value on the cell above it with simple Excel formula. Please help
For example: i want to find the last occurrence for "a" in the following table, it would return c

aba
aac
aba
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Thanks, that is what I was trying to clarify in post 5. :)

Anyway, I had the rows/columns the wrong way around by the look of it. :(
Try this instead.

20 08 15.xlsm
ABCDEF
1AcIInputc
2BcJResultD
3cFK
4DcL
5cGM
6EHN
7
Above last
Cell Formulas
RangeFormula
F2F2=INDEX(A1:C6,MAX(IF(A1:C6=F1,SEQUENCE(ROWS(A1:C6)),0))-1,AGGREGATE(14,6,SEQUENCE(,COLUMNS(A1:C6))/(INDEX(A1:C6,O4,0)=F1),1))
 
Upvote 0
=INDEX(A1:C6,MAX(IF(A1:C6=F1,SEQUENCE(ROWS(A1:C6)),0))-1,AGGREGATE(14,6,SEQUENCE(,COLUMNS(A1:C6))/(INDEX(A1:C6,O4,0)=F1),1))

IM sorry but what is this "O4"
 
Upvote 0
IM sorry but what is this "O4"
Sorry, that was part of my working that I missed tidying up.

The corrected (I hope) formula is in F2.
A shorter alternative to consider in F3. It assumed no cells will have text longer than 99 characters. If that is not a safe assumption and text could be longer, a modification could be made. Notice that the two ranges in this formula are both less than the whole table range. One omits the first row (if the last c is there we can't go above it) and one omits the last row (the result can never come from that row). This alternative could also fail if the table &/or texts are very large.

20 08 15.xlsm
ABCDEF
1AcIInputc
2BcJResultDD
3cFFFKDD
4DDcL
5cGMM MM
6EHN
7
Above last
Cell Formulas
RangeFormula
F2F2=INDEX(A1:C6,MAX(IF(A1:C6=F1,SEQUENCE(ROWS(A1:C6)),0))-1,AGGREGATE(14,6,SEQUENCE(,COLUMNS(A1:C6))/(INDEX(A1:C6,MAX(IF(A1:C6=F1,SEQUENCE(ROWS(A1:C6)),0)),0)=F1),1))
F3F3=SUBSTITUTE(RIGHT(SUBSTITUTE(TEXTJOIN(",",1,IF(A2:C6=F1,A1:C5,"")),",",REPT(",",99)),99),",","")
 
Upvote 0
Another option as below:

26Aug19.xlsx
ABCDEF
1AcI
2BcJcL A
3cF LK
4DcL A
5cGc
6EHN
Sheet53
Cell Formulas
RangeFormula
F2F2=INDEX(A1:C6,AGGREGATE(14,6,ROW(A1:C6)/(A1:C6=E2),1)-1,LOOKUP(2,1/(INDEX(A1:C6,AGGREGATE(14,6,ROW(A1:C6)/(A1:C6=E2),1),)=E2),COLUMN(A1:C6)))
 
Upvote 0
Formulas will mostly get affected by inserting preceding / inbetween rows or columns. Below update, using "ROW(A1:C6)-ROW(A1)+1" instead of "ROW(A1:C6)" and similarly with COLUMN, will resolve most insertions:


=INDEX(A1:C6,AGGREGATE(14,6,(ROW(A1:C6)-ROW(A1)+1)/(A1:C6=E2),1)-1,LOOKUP(2,1/(INDEX(A1:C6,AGGREGATE(14,6,(ROW(A1:C6)-ROW(A1)+1)/(A1:C6=E2),1),)=E2),COLUMN(A1:C6)-COLUMN(A1)+1))
 
Upvote 0
Another Option

It will matach even if there are two words Like in B3

Book1
ABCDEF
1AcI
2BcJFA
3cFLK
4DAc
5cFn
6EHN
7
Sheet2
Cell Formulas
RangeFormula
F2F2=INDEX($A$1:$C$6,INT(AGGREGATE(14,6,ISNUMBER(SEARCH(E2,$A$1:$C$6))*ROW($1:$6)*100+COLUMN($A:$C),1)/100)-1,MOD(AGGREGATE(14,6,ISNUMBER(SEARCH(E2,$A$1:$C$6))*ROW($1:$6)*100+COLUMN($A:$C),1),100))
 
Upvote 0
It will matach even if there are two words Like in B3
Are you sure? If you change cell C6 to "Nf" your formula returns "n". I suspect the OP would still want "A" returned?
 
Upvote 0

Forum statistics

Threads
1,215,266
Messages
6,123,962
Members
449,137
Latest member
yeti1016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top