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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
As you have marked bold in 3rd column so

Book1
HIJK
1aba
2aac
3aba
4
5
6
7
8
9
10c
11
12
13
Sheet3
Cell Formulas
RangeFormula
H10H10=INDEX(J:J,MATCH("ZZZZZZZZZZZ",J:J)-1)
 
Upvote 0
Alternatively, if you need an interactive formula to lookup different values, you can use the below

1597427622085.png


in cell A7 =INDEX(A1:C3,SUM(IF(MAX((B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3))=(B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3),ROWS(A1:C3)-1,"")),SUM(IF(MAX((B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3))=(B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3),COLUMN(A1:C3),"")))

it will change if you changed the value in cell A6

Best Regards
 
Upvote 0
Alternatively, if you need an interactive formula to lookup different values, you can use the below

View attachment 20396

in cell A7 =INDEX(A1:C3,SUM(IF(MAX((B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3))=(B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3),ROWS(A1:C3)-1,"")),SUM(IF(MAX((B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3))=(B6=A1:C3)*COLUMN(A1:C3)*ROW(A1:C3),COLUMN(A1:C3),"")))

it will change if you changed the value in cell A6

Best Regards
I like this one. However, when I input c it also returns c. It didn't return a. Is there away for it to return on the above cell?
 
Upvote 0
I am struggling to figure out how to find the last Occurrence in a table
Are you looking in the whole table or just that 3rd column in your example?

If the whole table then you will need to define what you mean by the last occurrence. For example, in the table below if we are looking for the last occurrence of c then the green one is last if we are looking by columns then rows but the blue one is last if looking by rows then columns.

If you are just looking in the third column then I have given a suggestion in F2.

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

20 08 15.xlsm
ABCDEF
1abbInputc
2bbcResultb
3aca
4
Above last
Cell Formulas
RangeFormula
F2F2=INDEX(C:C,AGGREGATE(14,6,ROW(C1:C3)/(C1:C3=F1),1)-1)
 
Upvote 0
I want to look in the entire table.
What I am using right now is look at each column individually and then use AGGREGATE. This way works however, it is very slow and cause excel to stop working.

Another method that i thought of is using the following:
=INDEX(A:C,MAX((A:C="a")*ROW(A:C)-1),MATCH("a",3:3,0))

However the "3:3" i have to input manually. Is there another way to input the lookup array for the match function using the row number?
 
Upvote 0
look at each column individually
So you are saying that if we were looking at my sample from post 5 then the 'last c' is the one in cell C2 and that is because it is in the right-most column containing a 'c'?

.. and thanks for updating your profile. (y)
 
Upvote 0
So you are saying that if we were looking at my sample from post 5 then the 'last c' is the one in cell C2 and that is because it is in the right-most column containing a 'c'?
If that is the case, then see if this works for you.

20 08 15.xlsm
ABCDEF
1AEIInputc
2BcJResultF
3cFK
4DcL
5cGM
6cHN
7
Above last
Cell Formulas
RangeFormula
F2F2=INDEX(INDEX(A1:C6,0,MAX(IF(A1:C6=F1,SEQUENCE(,COLUMNS(A1:C6)),0))),AGGREGATE(14,6,SEQUENCE(ROWS(A1:C6))/(INDEX(A1:C6,0,MAX(IF(A1:C6=F1,SEQUENCE(,COLUMNS(A1:C6)),0)))=F1),1)-1)
 
Upvote 0
Thank you so much for the fast response. I am looking for right most and bottom most. In this case it should return the value in cell a5 since the last "c" is in cell A6
 
Upvote 0
I am looking for right most and bottom most. In this case it should return the value in cell a5 since the last "c" is in cell A6
So in post 5 the 'last c' is the blue one?
 
Upvote 0

Forum statistics

Threads
1,215,275
Messages
6,124,002
Members
449,137
Latest member
abdahsankhan

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