Solved

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

Posted on 2006-11-27
7
5,721 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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