Vlookup - last match

Exceler8

New Member
Joined
May 16, 2003
Messages
33
I'm sure something like this has been discussed before... but I couldn't find anything.

I am essentially trying to do a Vlookup, but returning the last value to match, rather than the first. To be exact, here is what I have:

ID Value
1 10
2 10
3 10
4 10
1 20
3 10
1 40

I am trying to retrieve the most recent value, for the ID = 1. A conventional vlookup will give me the value "10"... but I want the value "40".

Any ideas?

TIA.
 
Hi Aladin,

I have experimented with the formula and it just shows up with #n/a - also when I try define Drange and Erange instead of ALL! It just defaults to the name of the workbook as below;


=ALL!$E$2:INDEX(ALL!$E:$E,"Book 1.xlsx'!Lrow

Dis you have any ideas as to why this is? Thanks
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Also further to this, the values in column E are letters, not numeric - is this an issue? Thanks again.
 
Upvote 0
Also further to this, the values in column E are letters, not numeric - is this an issue? Thanks again.

Let's get this straight.

1) The sheet housing the data is named ALL.
2) You want to automatically include new data.
3) As you state above, the range in column E houses letters (text), not numbers.

A question: What does the range in column D house - text or numbers?
 
Upvote 0
Let's get this straight.

1) The sheet housing the data is named ALL.
2) You want to automatically include new data.
3) As you state above, the range in column E houses letters (text), not numbers.

A question: What does the range in column D house - text or numbers?

Hi - sorry if my wording has been unclear so far, as I am quite novice at excel. This forum I must admit has been fantastic so far. Just to answer the questions that you asked.

1) The sheet housing the data is named ALL
2) I want to be able to include new data should it be updated
3) Column E houses letters. Column B houses date (i.e. numbers). Column J houses numbers. These are three columns I need to look up the second last values of.

I have attached an example file for you - hopefully this helps as to what I am looking for. This is a smaller much condensed version of the file I am dealing with. Thank You
 
Upvote 0
<style> <!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";} @page {margin:1.0in .75in 1.0in .75in; mso-header-margin:.5in; mso-footer-margin:.5in;} td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Calibri, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;} .xl63 {mso-number-format:"Short Date";} --> </style>Below is an example similar to the ALL sheet I am dealing with, hopefully this is of assistance

A
BCDEFGHIJKL
AA11/01/11XABCY225
AA21/03/11BBCN426
AA32/05/11CNNN922
AA43/08/11CBCY888
AA523/01/12FOXN726
AA624/01/12ABCY455
AA725/01/12BBCN77
AA826/01/12CNNY92
AA927/01/12CBCN89
AA1028/01/12FOXY66
AA1129/01/12ABCN44
AA1230/01/12BBCN66
AA1331/01/12CNNN28
AA141/02/12CBCN827
AA152/02/12FOXY466
AA163/02/12ABCY924
AA174/02/12BBCY899
AA185/02/12CNNN226
AA196/02/12CBCN887
AA207/02/12FOXY26

<col style="width:65pt" span="12" width="65"> <tbody>
</tbody>

And below is an example of what the sheet "Lookup" looks like

HEADINGHEADING
ABCSecond Last E
Second Last BSecond Last J
BBC
CNN
CBC
FOX

<col span="5"><col span="2"><col span="2"><tbody>
</tbody>

Thank You.
 
Upvote 0
Hi - sorry if my wording has been unclear so far, as I am quite novice at excel. This forum I must admit has been fantastic so far. Just to answer the questions that you asked.

1) The sheet housing the data is named ALL
2) I want to be able to include new data should it be updated
3) Column E houses letters. Column B houses date (i.e. numbers). Column J houses numbers. These are three columns I need to look up the second last values of.

I have attached an example file for you - hopefully this helps as to what I am looking for. This is a smaller much condensed version of the file I am dealing with. Thank You

<style> <!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";} @page {margin:1.0in .75in 1.0in .75in; mso-header-margin:.5in; mso-footer-margin:.5in;} td {padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:black; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Calibri, sans-serif; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;} .xl63 {mso-number-format:"Short Date";} --> </style>Below is an example similar to the ALL sheet I am dealing with, hopefully this is of assistance
[...]
Thank You.

The ALL sheet, A:J...
Date
AA11/1/2011XABCY 225
AA21/3/2011 BBCN 426
AA32/5/2011 CNNN 922
AA43/8/2011 CBCY 888
AA523/01/12 FOXN 726
AA624/01/12 ABCY 455
AA725/01/12 BBCN 77
AA826/01/12 CNNY 92
AA927/01/12 CBCN 89
AA1028/01/12 FOXY 66
AA1129/01/12 ABCN 44
AA1230/01/12 BBCN 66
AA1331/01/12 CNNN 28
AA141/2/2012 CBCN 827
AA152/2/2012 FOXY 466
AA163/2/2012 ABCY 924
AA174/2/2012 BBCY 899
AA185/2/2012 CNNN 226
AA196/2/2012 CBCN 887
AA207/2/2012 FOXY 26

<colgroup><col style="width: 48pt;" width="64"> <col style="width: 81pt; mso-width-source: userset; mso-width-alt: 3840;" width="108"> <col style="width: 48pt;" span="2" width="64"> <col style="width: 53pt; mso-width-source: userset; mso-width-alt: 2531;" width="71"> <col style="width: 48pt;" span="5" width="64"> <tbody>
</tbody>

Lrow, Scope ALL:
Rich (BB code):
=MATCH(9.99999999999999E+307,ALL!$B:$B)
Brange, Scope Workbook:
Rich (BB code):
=ALL!$B$2:INDEX(ALL!$B:$B,ALL!Lrow)
Drange, Scope Workbook:
Rich (BB code):
=ALL!$D$2:INDEX(ALL!$D:$D,ALL!Lrow)
Erange, Scope Workbook:
Rich (BB code):
=ALL!$E$2:INDEX(ALL!$E:$E,ALL!Lrow)
Jrange, Scope Workbook:
Rich (BB code):

=ALL!$J$2:INDEX(ALL!$J:$J,ALL!Lrow)

The Lookup sheet, A:E...
Second Last ESecond Last BSecond Last JIdx
ABCN29/01/124411
BBCN30/01/126612
CNNN31/01/122813
CBCN1/2/201282714
FOXY2/2/201246615

<colgroup><col style="width: 48pt;" width="64"> <col style="width: 97pt; mso-width-source: userset; mso-width-alt: 4579;" width="129"> <col style="width: 103pt; mso-width-source: userset; mso-width-alt: 4892;" width="138"> <col style="width: 99pt; mso-width-source: userset; mso-width-alt: 4693;" width="132"> <col style="width: 48pt;" width="64"> <tbody>
</tbody>

B2, copied down:
Rich (BB code):
=INDEX(Erange,$E2)
C2, copied down:
Rich (BB code):
=INDEX(Brange,$E2)
D2, copied down:
Rich (BB code):
=INDEX(Jrange,$E2)
E2, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=LARGE(IF(Drange=$A2,ROW(Drange)-ROW(INDEX(Drange,1,1))+1),2)

See:
https://dl.dropbox.com/u/65698317/aaConditionalSecondLastValue%20Public%20ls23%20.xlsx
 
Upvote 0
I'd like to use the above function in Google Spreadsheet, unfortunately it does not support 'Lookup' function, any work around to achieve the same result ?

TIA

Google Spreadsheet seems to understand:

=VLOOKUP(9.99999999999999E+307,H2:H6,1,1)

if H2:H6 is numeric, and

=VLOOKUP(REPT("z",255),J2:J6,1,1)

if J2:J6 is text in that the formulas return the last numeric value and the last text value like in Excel.

However, it does not process the following as expected:

=VLOOKUP(9.99999999999999E+307,IF(G2:G6="Lion",H2:H6),1,1)

in that the IF bit is not admitted as a reference. (error: Argument must be a range.)

Having the IF bit as a separate formula creates a correct result, a reference, the foregoing VLOOKUP formulas cannot process properly as they do with the manually created references.

Conclusion: The Excel formula you want to implement does not seem possible in Google Spreadsheet. As I noted on a few occasions, Gnumeric and OpenOffice.org Calc behave the same way as Excel.
 
Upvote 0
Thanks...I just had a similar problem and was able to use this solution. I didn't have to submit a new question.
It's amazing to me everything Excel can do. IF I want something I can usually create it (along with google and MrExcel). Guess I need to use Excel more so I learn more.

The condition (A1:A10=C1) returns, after coercing, 1 for match and 0 for no match

E.g. an array like:

{0;0;0;1;0;0;1;0}


If you devide 1 by that array, 1/(A1:A10=C1) it will look like:

{#DIV/0!;#DIV/0!;#DIV/0!;1;#DIV/0!;#DIV/0!;1;#DIV/0!}

A lookup with LOOKUP formula and a lookup value greater than any value in the range will return the last numerical value i.e. the last 1, representing the last match.
 
Upvote 0
Unable to understand this, can you please give me some more accurate example for this?

I thought this was the formula I also needed but I'm hoping someone can help me tweak it just a bit. I have a similar situation in which I want a vlookup type formula that will give me the last value but the last non-zero value.

For example my table looks something like this:

name date
Colby 3/5/2009
Colby 4/9/2009
Colby 5/2/2009
Colby
Tom 3/3/2009
Tom
Tom 4/1/2009
Tom

In this case using that formula to search for Colby will result me 0 as the last Colby doesn't have a date but what I really want is the last non-zero value. Can anyone help me?
 
Upvote 0

Forum statistics

Threads
1,215,306
Messages
6,124,160
Members
449,146
Latest member
el_gazar

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