Return Most Right Value

AntNMC1

New Member
Joined
Sep 20, 2012
Messages
14
Below is a simple table. I would like to know of a formula that will look for the latest date within a row, taking into consideration of matching dates, and return the farthest right header.

[TABLE="width: 336"]
<colgroup><col><col span="4"></colgroup><tbody>[TR]
[TD]Dates[/TD]
[TD="align: right"]HD1[/TD]
[TD="align: right"]HD2[/TD]
[TD="align: right"]HD3[/TD]
[TD="align: right"]HD4[/TD]
[/TR]
[TR]
[TD]1st[/TD]
[TD="align: right"]1/1/2018[/TD]
[TD="align: right"] 1/2/2018[/TD]
[TD="align: right"]1/2/2018[/TD]
[TD="align: right"]1/2/2018[/TD]
[/TR]
[TR]
[TD]2nd[/TD]
[TD="align: right"]2/5/2018[/TD]
[TD="align: right"] 2/5/2018[/TD]
[TD="align: right"][/TD]
[TD="align: right"] [/TD]
[/TR]
[TR]
[TD]3rd[/TD]
[TD="align: right"]1/15/2018[/TD]
[TD="align: right"] 1/16/2018[/TD]
[TD="align: right"] 1/16/2018[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]4th[/TD]
[TD="align: right"]2/26/2018[/TD]
[TD="align: right"]2/26/2018[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]

Thus, column next to HD4 should look like this:
FORMULA
HD4
HD2
HD3
HD2

Thank you!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
With your posted data in A1:E5, this formula returns the header of the last referenced date
Code:
F2: =LOOKUP(99^99,B2:E2,$B$1:$E$1)
Copy that formula down through F5

Is that something you can work with?
 
Upvote 0
Ron,

Thank you. A follow-up question: what does the 99^99 mean? Out of the formula you provided, I do not how to understand this part.

Thank you
 
Upvote 0
The LOOKUP function has a neat feature (flaw?) that can be exploited.
If your search number is larger than any value in the list....the lookup function returns the LAST numeric value in the list.
As long as the search number is larger than any possible value the correct value will be returned. I used 99^99 because it's so easy to type. Does that help?
 
Upvote 0
Here is another formula that would work. I am not sure if it would be better than Ron's formula as it involves two function calls instead of one (INDEX is a very fast function though), but given that caveat...

=INDEX(B$1:E$1,,COUNT(B2:E2))
 
Upvote 0
Here is another formula that would work. I am not sure if it would be better than Ron's formula as it involves two function calls instead of one (INDEX is a very fast function though), but given that caveat...

=INDEX(B$1:E$1,,COUNT(B2:E2))

In case of an empy cell in-between two numbers, this will flounder and it's never faster than:

=LOOKUP(9.99999999999999E+307,B2:E2,$B$1:$E$1)

when both apply. That big number is there, not because I have insensitive fingers.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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