Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Referring to the Last Cell.

# Referring to the Last Cell

by Allen Wyatt
(last updated December 9, 2017)

There may be times when you are putting together a workbook and you want to keep a summary on one worksheet and detail information on another. For instance, let's suppose Sheet1 is your summary worksheet, and you have detailed information for bank accounts on Sheet2. In looking at the detail information, you have dates in column A, and balances for different accounts in columns B, C, and D. Thus, the detailed information is a table that shows a running progression of bank balances on different dates.

In putting together your summary information on Sheet1, you realize that you need to reference the last figures in columns B, C, and D. These figures represent the latest balances, and thus are perfect for your summary. How do you do it? Particularly when you continue to add information to your detail worksheet over time?

Actually, there are several ways to approach the problem. (There are typically several ways to solve any Excel problem.) One way is to use the VLOOKUP function. At the point in the summary where you want the latest balance from column B of the detail (Sheet2), you would put the following formula:

```=VLOOKUP(MAX(Sheet2!\$A:\$A),Sheet2!\$A:\$D,2)
```

To change references for the other two account balances, you would simply change the last number (2) to either 3 (for the account in column C) or 4 (for the account in column D). The function works because it looks up the maximum value in column A, which contains dates. It then looks in the data table (Sheet2!\$A:\$D) and finds the appropriate offset for the desired column.

This approach works fine, provided there are no dates in column A past the last balances entered. If there are, then the values returned will always be incorrect.

Another way to approach the problem is to use the INDEX function in conjunction with either COUNT or COUNTA. If the detail columns don't contain any text (even in the column headers), then you would use the COUNT function. If there is text included, then COUNTA is preferred. At the point where you want to include the last balance from column B of the detail, you would use the following formula:

```=INDEX(Sheet2!B:B,COUNTA(Sheet2!B:B))
```

It looks into the table, determines the number of non-blank cells in column B, and then pulls the figure from that last non-blank cell. To adapt the formula for columns C and D, simply change the B references to the appropriate C or D.

Still another way to deal with the problem is to use the OFFSET function, as in the following:

```=OFFSET(Sheet2!B1,COUNTA(Sheet2!B:B)-1,0)
```

This function returns the value of a cell offset from a base reference cell. In this case, the base cell is Sheet2!B1. The COUNTA function is used to determine how many rows to offset from the base, and the 0 specifies that the offset should be in the same column as the base reference. To change the formula for columns C and D, simply change all references to B to either C or D.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12470) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Referring to the Last Cell.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Leaving a Cell Value Unchanged If a Condition Is False

Ever want the IF function to only return a value if the condition it is testing is true, and not if the condition is ...

Discover More

Dealing with Midnight Ending a Day

Dealing with times in Excel is fairly straightforward, except when it comes to midnight. Some people prefer that midnight ...

Discover More

Word Tracks Changes to Changes

When you have Track Changes turned on for a document, Word remembers which editor made which changes. If this behavior ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

##### More ExcelTips (ribbon)

Totaling Across Worksheets

Want to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same ...

Discover More

Summing Only Positive Values

If you have a series of values and you want to get a total of just the values that meet a specific criteria, then you ...

Discover More

Checking for Either of Two Text Values

Using a formula to find information in a text value is easy. Using a formula to find either of two text values within a ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. Youâ€™ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 + 6?

2020-10-17 22:57:37

Roy

Regarding Ken Kast's post, I must say I usually will NOT go to the "exceljet.net" website, basically for any reason other than mistake.

The reason is that it make incredibly massive use of memory. Usually I would be using IE and going to a single page yanks me from, maybe, 150MB up to 1,100MB immediately. Open another page? Add 150-250MB each. That pretty much kills IE fairly immediately so... Decided to test it with Edge because of Mr. Kast's post and it yanked Edge right up to 1,105MB the instant it opened.

It's like every 3-letter government agency has added code to that site... or something... seriously, it has to be massive ads running massive scripts and such, and you know a massive number of ads accessing, not even putting an ad up, just accessing your browser like that, one or more must be doing something horrible.

So, never going there for any reason on God's Green Earth again. I had great hopes it was just some IE thing, maybe the first good reason I'd ever heard for stopping use of IE but noooo... NOT an IE thing at all. So... and it's a shame. The guy seems to have plenty, and I do mean plenty, of good stuff. Shame. Must be very dollarizing, but I won't ever go again after tonight.

The point of the website's content in this case is to use the following, or a variant that fits your circumstance:

=LOOKUP(2,1/(NOT(ISBLANK(A:A))),ROW(A:A))

I modified for adding 1 to it and also to limit the ranges, so not A:A but rather A1:A12000. The lag was tremendous with A:A. But the other thing it does is my old OFFSET() used a COUNTA() in it and if our data included any random empty cell in the column being ckecked, well... too bad.

It would also be easy to modify for starting somewhere other than first row, and so on. I fed it into an ADDRESS() function since my need is for an address, but it would have lots of other uses. Say, this minus COUNTA() would tell you if ou have empty cells in a given column or row. I bet there's a hundred other ways it would be useful.

2017-12-09 18:14:58

Ken Kast

These formulae are pretty opaque. If one is auditing a workbook it would probably take some time to figure out what is going on here. Besides that I do not think the solutions relying on COUNTA work in all cases. In particular, if there is a blank is a cell, then COUNTA will not point to the last row; it points to the row number corresponding to the number of non blanks. As an example, if the data set looks like
4

3
2

1
COUNTA is 4 but the last row is 6.

This site has a solution which accounts for "strange" cells: https://exceljet.net/formula/get-value-of-last-non-empty-cell

2017-12-09 06:55:01

Mike Hodkinson

Excellent item on referring to the last cell. Took this one stage further and what if you needed to find the address of the last cell in a column by formula. Found =ADDRESS(COUNTA(Sheet1!B:B),COLUMNS(2)) does this for you. Hope this is of interest.

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."