
Tips.Net > ExcelTips Home > Formulas > Retrieving the Last Value in a Column
Summary: Sometimes you need to grab the last value entered in a column, even when you keep pushing that last value downwards by adding data to the column. There are a number of ways you can get just the data you need. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
You may wonder if there is a way to return the last (not largest) value in a column. For instance, if there are values in A1 through A5, then you may want the value in A5 returned. Later, if values were added in A6 through A8, then the value in A8 should be returned.
There are a couple of ways that a solution can be approached. The first is to use a formula such as the following:
=INDEX(A:A,COUNT(A:A))
This formula returns the last numeric value in a column, providing that the values begin at (in this case) A1. This approach only works if all the values in the column are numeric. If the values are non-numeric, or if there are blank cells intermixed with the values, then a different approach is necessary. One way is to copy the following formula into column B, just to the right of the cells that may contain values:
=IF(ISNUMBER(A2),IF(A2<>0,ROW(A2),""),"")
In this case, the formula returns the row number of any cell in A which contains a numeric value greater than zero. The following formula can then be used to retrieve the last value in column A:
=INDEX(A:A,MAX(B:B))
This formula works because it returns the largest row number from column B, and then uses that as an index to return the corresponding value from column A.
As you can tell, returning the last value in a column can get a bit tricky at times. A clean approach is to simply develop your own VBA function that returns the desired value. In this case you can program the function to return any value—not just numeric values. A fine example of such a function is available at John Walkenbach's Web site. Check out the following:
http://j-walk.com/ss/excel/tips/tip30.htm
Tip #2512 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
PivotTables Got You Perplexed? Learn the ins and outs of this powerful data-crunching tool. ExcelTips: PivotTables for the Faint of Heart makes it easy.
No, not that type of date. If you need to do any types of work with calendar dates, Excel has the tools you need. Learn how to use those tools the easy way. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site