Solved

excel--find last occurrence of a value in a range.

Posted on 2006-11-27
7
5,563 Views
Last Modified: 2011-08-18
How would I find the last occurrence of a non-unique value in a range. Although LAST isn't a function, but something like this for example: IF(LAST(value,range)*TRUE,"last occurrence","").
Thank you
0
Comment
Question by:cwest1
  • 5
  • 2
7 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 18024977
Hi cwest1,
If you want to find the index number of the last occurrence of a value in a range, then try an array formula like:
=IF(COUNTIF(I4:I11,"b")=0,"",MAX(IF(I4:I11="b",ROW(I4:I11)-ROW(I4)+1,"")))
Array formulas need to be entered in a special way: hold the Control and Shift keys down, then press Enter. Excel should respond by adding curly braces { } surrounding the formula. If it doesn't, then select the cell, click in the formula bar and CTRL + Shift + Enter.

In this formula, the range being searched is I4:I11 and the value being sought is "b". If the value sought isn't present, the formula returns an empty string.

Hoping to be helpful,

Brad
0
 
LVL 81

Expert Comment

by:byundt
ID: 18024983
cwest1,
If you don't want to find an index number, could you please post a simple example and show the expected result?
Brad
0
 
LVL 81

Expert Comment

by:byundt
ID: 18025169
cwest1,
If you want to find the last value in a range, then consider using the LOOKUP function. It returns the last value if it cannot find a match.
=LOOKUP("zzzzz",I4:I11)            finds the last text value in the range I4:I11. The string zzzzz is sure to be last in an alphabetical sort of the range.
=LOOKUP(1E40,I4:I11)                finds the last numeric value in the range I4:I11. The value 1E40 is a number so large it won't be found in the range.
Brad
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cwest1
ID: 18025325
Thanks Brad. Got me going in right direction :)

The spreadsheet I'm working with contains dates in column A and customer numbers in column I. The same customer number occurs several times in column I. I want to get the latest date a customer number occurred in column I. Column T contains unique customer numbers. The following appears to work. Appreciate any comments.

{=IF(T2<>"",INDEX($A$2:$I$744,MAX(IF($I$2:$I$744=T2,ROW($I$2:$I$744),"")),1),"")}
0
 
LVL 81

Accepted Solution

by:
byundt earned 250 total points
ID: 18025483
In my original formula, I used the COUNTIF function to make sure that the value being sought actually occurs in the range being searched. You know your data better--is it sufficient to test whether T2="" ?

You are basing your INDEX on A2:I744 -- but using the ROW function without subtracting 1 (ROW returns the series 2 through 744, but you need 1 through 743 for the INDEX).

You are also returning a value from column A, so the INDEX function doesn't need to refer to column I. The only reason for including more columns in the INDEX range would be if you are planning to change the column index 1 as you copy the formula across. If you restrict the INDEX range to column A, then it won't recalc if there is a change to columns B through I -- a potential improvement in workbook recalc time.

Here is how I think your formula should be written:
{=IF(T2="","", INDEX($A$2:$A$744,MAX(IF($I$2:$I$744=T2,ROW($I$2:$I$744)-1,"")),1))}

Brad
0
 

Author Comment

by:cwest1
ID: 18025507
Thanks Brad. Much appreciated.
0
 
LVL 81

Expert Comment

by:byundt
ID: 18025512
cwest1,
Thanks for the grade!
Brad
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help to break down spreadsheet 3 41
Hosted Exchage 3 22
Copy and paste Excel Shapes using vba 6 23
How to always round a decimal up 5 23
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question