Finding the last text value based on cell value in another column

BiggusDoggus

Board Regular
Joined
Jul 7, 2014
Messages
88
Hi all

So I have a table of data - here is an example:


ABC
1CodeStageFinal Stage
2455Stage 1
3455Stage 2
4522Stage 1
5522Stage 1
6616Stage 1
7616Stage 2
8616Stage 3
9616Stage 4


What I'm wanting in column 3 is a formula to return the stage in column B relating to the last occurrence of the code in column A.

So - for code 455 it would be Stage 2, code 522 Stage 1, code 616 Stage 4.

I can't use MAX obviously because that doesn't work for text values, but I have been unable to locate an alternative.

Any help appreciated please!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
12,212
How about?

Book2
ABCD
1CodeStageFinal Stage
2455Stage 1Stage 2Stage 2
3455Stage 2Stage 2 
4522Stage 1Stage 1Stage 1
5522Stage 1Stage 1 
6616Stage 1Stage 4Stage 4
7616Stage 2Stage 4 
8616Stage 3Stage 4 
9616Stage 4Stage 4 
10
Sheet12
Cell Formulas
RangeFormula
C2:C9C2=LOOKUP(2,1/($A$2:$A$10=A2),$B$2:$B$10)
D2:D9D2=IF(COUNTIF($A$2:$A2,A2)=1,LOOKUP(2,1/($A$2:$A$10=A2),$B$2:$B$10),"")


The D2 formula is if you only want to show the result on the first matching line.
 

Toadstool

Well-known Member
Joined
Mar 5, 2018
Messages
2,549
Office Version
  1. 2016
Platform
  1. Windows
Hi BiggusDoggus,

This formula should do what you ask:

BiggusDoggus.xlsx
ABC
1CodeStageFinal Stage
2455Stage 1Stage 2
3455Stage 2Stage 2
4522Stage 1Stage 1
5522Stage 1Stage 1
6616Stage 1Stage 4
7616Stage 2Stage 4
8616Stage 3Stage 4
9616Stage 4Stage 4
Sheet1
Cell Formulas
RangeFormula
C2:C9C2=IF(A2="","",INDEX($B$2:$B$15,AGGREGATE(14,6,ROW($A$2:$A$15)-ROW($A$1)/($A$2:$A$15=A2),1)))
 

BiggusDoggus

Board Regular
Joined
Jul 7, 2014
Messages
88

ADVERTISEMENT

How about?

Book2
ABCD
1CodeStageFinal Stage
2455Stage 1Stage 2Stage 2
3455Stage 2Stage 2 
4522Stage 1Stage 1Stage 1
5522Stage 1Stage 1 
6616Stage 1Stage 4Stage 4
7616Stage 2Stage 4 
8616Stage 3Stage 4 
9616Stage 4Stage 4 
10
Sheet12
Cell Formulas
RangeFormula
C2:C9C2=LOOKUP(2,1/($A$2:$A$10=A2),$B$2:$B$10)
D2:D9D2=IF(COUNTIF($A$2:$A2,A2)=1,LOOKUP(2,1/($A$2:$A$10=A2),$B$2:$B$10),"")


The D2 formula is if you only want to show the result on the first matching line.
The D2 formula is perfect - thank you!
 

BiggusDoggus

Board Regular
Joined
Jul 7, 2014
Messages
88
Do you mean this?

Book1
ABCD
1CodeStageFirst StageFinal Stage
2455Stage 1Stage 1Stage 2
3455Stage 2  
4522Stage 1Stage 1Stage 1
5522Stage 1  
6616Stage 1Stage 1Stage 4
7616Stage 2  
8616Stage 3  
9616Stage 4  
Sheet3
Cell Formulas
RangeFormula
C2:C9C2=IF(COUNTIF($A$2:$A2,A2)=1,B2,"")
D2:D9D2=IF(COUNTIF($A$2:$A2,A2)=1,LOOKUP(2,1/($A$2:$A$10=A2),$B$2:$B$10),"")

That would be it, yes thank you! And to have the value appear on every matching line please?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,446
Messages
5,837,292
Members
430,493
Latest member
prontonz

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
Top