Solved

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

Posted on 2006-11-27
7
5,109 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 80

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 80

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 80

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 80

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 80

Expert Comment

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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
This article will show you how to use shortcut menus in the Access run-time environment.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now