Return the last value in a list

Excel Tip #025

Return the last value in a list

You would have faced some situations where you want to get the last value in the list. And this list will not be static, the list will grow further and still the the last value has to be returned. Quite interesting...!

There might be multiple ways but as far I know, there are 2 ways in which we can get this done. But as far I consider, there are loopholes in all the 2 methods. Let us get in detail with all the 2 methods.

Method 1

This method uses the function LOOKUP. Let us see get to know about this function.

LOOKUP function returns a value from a range (one row or one column) or from an array. The syntax is:
LOOKUP( lookup_value, lookup_range, [result_range] )
(or)
LOOKUP( lookup_value, lookup_range )

We are going to use a hidden excel function in this method which is 9e9. So what does this 9e9 give? 9e9 is just a notation for 9,000,000,000 which is considered as the largest value in the array. It is nothing like an exponential function, 9 followed by 9 zeroes in short.

The formula is,
=LOOKUP(9e9,A:A)

Once you type this formula, 9e9 gets converted to 9,000,000,000. The formula will return the last value as the list grows.
Method 1 - LOOKUP & 9e9
Loophole - Method 1:

1) It is used only for values and doesn't consider character in the list
2) The values need not be continuous. If you enter a number in cell A20 leaving cells A11 to A19 as blank, it will return the value entered in A20. This is a loophole because, if accidentally entered a number at the end, and then sending the report as it is will screw up everything.

Method 2

This method uses the functions INDEX & COUNT/COUNTA.

INDEX - Returns a value in a table based on the intersection of a row and column position within that table
COUNT - Counts the numbers of cells in a range that contain numbers
COUNTA - Counts the numbers of cells in a range that are not empty (doesn't consider whether it is number or character)

The formula is,
=INDEX(A:A,COUNTA(A:A))
Method 2 - INDEX & COUNT
One main advantage in this method is if you use COUNTA function, then we can make use for character (or) for strings too.

Loophole - Method 2:

1) If you are using COUNT and if there are any blank values in between, the result will not be proper. The list should be continuous and the values should start from cell 1.

So which of these methods will you be using?

Comments

Popular posts from this blog

VLOOKUP - Exact Match & Approximate Match

Row 1 Is Missing. How to unhide?

Search Backwards in Excel