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

BiggusDoggus

Board Regular
Joined
Jul 7, 2014
Messages
86
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!
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
10,109
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
961
Office Version
2016
Platform
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
86

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
86
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?
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,624
Messages
5,512,465
Members
408,898
Latest member
Glenno557

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top