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

#### BiggusDoggus

##### Board Regular
Hi all

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

 A B C 1 Code Stage Final Stage 2 455 Stage 1 3 455 Stage 2 4 522 Stage 1 5 522 Stage 1 6 616 Stage 1 7 616 Stage 2 8 616 Stage 3 9 616 Stage 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.

### 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.

#### mrshl9898

##### Well-known Member
Are the Codes always consecutive?

=INDEX(B2:B\$9,COUNTIF(A2:A\$9,A2))

#### Eric W

##### MrExcel MVP

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.

##### Well-known Member
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

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

Sorry to bump this - but what would the formula be to get the FIRST text value please?

#### Eric W

##### MrExcel MVP
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),"")

#### BiggusDoggus

##### Board Regular
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?

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.

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.

### Which adblocker are you using?

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

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