Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. 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: Referencing the Last Cell in a Column.

Referencing the Last Cell in a Column

Written by Allen Wyatt (last updated January 22, 2024)
This tip applies to Excel 2007 and 2010


27

Patty asked about a common scenario, in which column B contains quite a bit of data, and information can be added to the cells in the column at any time. In a formula in cell C4, Patty wants to see the value at the bottom of those cells in column B that contain values. Thus, if cells B1:B27 contain data, then in cell C4 Patty wants to see the value that is in cell B27. If three more pieces of data are added to column B, then the value in C4 should contain the value in B30.

The solution to this problem depends on whether you can count on the data in column B containing blank cells or not. If the data is contiguous—it doesn't contain any blank cells—then you can use the following formula in C4:

=INDIRECT("B"&COUNTA(B:B))

This constructs an address based on the last cell in the column, and then uses the INDIRECT function to return the value at that address.

If it is possible for there to be blanks in column B, then the following formula will work:

=INDIRECT("B"&MAX(ROW(1:1048576)*(B1:1048576<>"")))

Again, the INDIRECT function is used to fetch the actual value, but the address used by INDIRECT is put together differently.

A different approach is to use the VLOOKUP function to return the value. If column B consists of numeric values, then the following formula in C4 will work just fine:

=VLOOKUP(9.99999999999999E+307,B:B,1)

If column B contains text, then the numeric lookup won't work, but the following will:

=VLOOKUP(REPT("z",50),B:B,1)

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

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

Getting Rid of the Ctrl+Click Message

When you add a hyperlink to a document, you can later click that link to display whatever is linked to. Beginning in Word ...

Discover More

Automatically Inserting Tomorrow's Date

Do you routinely need to work with tomorrow's date? Why not create a template that automatically adds tomorrow's date to ...

Discover More

Controlling the Plotting of Empty Cells

When creating a chart from information that contains empty cells, you can direct Excel how it should proceed. This tip ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Uncovering and Removing Links

Excel allows you to reference data in other workbooks by establishing links to that data. If you later want to get rid of ...

Discover More

Swapping Two Cells

If you need to swap the contents of two cells in your worksheet, Excel provides a number of ways you can approach the ...

Discover More

Sequentially Inputting Information

When entering data in a worksheet, you may only want to add information to the cells in a particular range. You can ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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}] (all 7 characters, in the sequence shown) 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 6 + 5?

2021-09-22 11:51:10

NHC

I'm using =INDIRECT("B"&COUNTA(B:B)) but it's returning a cell in the middle of the column. There are no blanks but some cells within the column has basic =SUM formulas. Can someone please assist?


2015-12-30 06:05:12

Barry

NOTE: The formulas using the MAX function are "array" formulas and therefore need to be entered using the 'Ctrl+Shift+Enter" key combination for it to work correctly.


2015-07-21 09:47:29

Parker

I am using the Vlookup one with great success I just need to have it omit any cell with a (0) in it. any help would be great.


2015-04-16 11:40:54

Chuck Trese

Scott,
There are many methods, each has it's pros and cons. Here is a fairly foolproof method, based on your question.

Range("A"& cells.Rows.Count).End(xlUp)

This method starts in column A, goes all the way to the bottom, then does the equivalent of Ctrl-UpArrow to find the last non-empty cell. The up-side to this one is that it looks for anything other than an empty cell. The down-side to this one is that if you have a formula in the cell that returns "", it can still give you that 'empty' cell, because this method does not consider a formula as empty.


2015-04-16 11:38:14

Michael

Your original method works fine, unless the target is on a remote worksheet. e.g.,
I have an existing formula:
=VLOOKUP(B143,'Daily >0 5-minute'!E$12252:G$18791,2,FALSE)
in which I would like to replace "18791" with the row of the current last cell. I can find that value easily with
=COUNTA('Daily >0 5-minute'!A:A)
but all my attempts to embed that formula in the VLOOKUP argument have resulted in a variety of errors.


2015-04-15 13:52:13

Scott Levy

How would you use this last cell in a column formula in a macro to set the name range from $A$1 to the "LAST CELL"


2015-02-01 08:34:10

JMJ

Yep, it DOES help!
Thanks!


2015-01-31 13:30:57

Willy Vanhaelen

@JMJ
My version is 2007. I had the same problem with some array formulas in former versions. Try to restrict your range as for instance:

=LOOKUP(2,1/(A1:A10000<>""),A1:A10000)

Perhaps that helps.


2015-01-31 08:24:03

JMJ

@Willy
Yes tour formula is very nice and concise, but... Before writing my formula, I did tried yours, but I did not succeed in getting it to work: it gives a #NUMBER error, seemingly from the A:A<>"" part(?)
Maybe we have different XL versions? Mine is 2003 SP3...


2015-01-30 13:39:45

Willy Vanhaelen

Why use so a lenghty formula when this very short one does the same job?

=LOOKUP(2,1/(A:A<>""),A:A)


2015-01-30 11:52:57

JMJ

A formula that works on the whole column, whether it contains only numbers, only characters or both, with or without blank cells:
=IF(ISNA(MATCH(9^15,B:B)),INDIRECT("B"&MATCH("*",B:B,-1)),IF(ISNA(MATCH("*",B:B,-1)),INDIRECT("B"&MATCH(9^15,B:B)), INDIRECT("B"&MAX(MATCH(9^15,B:B),MATCH("*",B:B,-1)))))
A bit lengthy, but thoroughly tested.
Hope this helps.


2015-01-28 07:28:15

Willy Vanhaelen

@ Alfred and Micky

Better even use A:A<>"" when you want a 0 value or a formula returning 0 to be included.


2015-01-27 14:27:04

Michael (Micky) Avidan

@Alfred,
You will be better off with the use of: A:A<>0 especially in cases of a negative value.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2015-01-27 12:26:57

Alfred Polan

This short formula will do the job of looking up the last item in a column rather than all of the fancy stuff. =LOOKUP(2,1/(A:A>0),A:A)


2015-01-27 09:55:47

Chuck Trese

I like that David - at least for cases where a table fits the need. Nice and simple.
Building off your idea, here's a generic form (won't break if you move your table).

=INDEX(Table2,ROWS(Table2))


2015-01-27 04:45:25

David Sheen

Why not just convert the column to a single column table. The formula =OFFSET($B$1,ROWS(table1),0) should always return the value in the last cell.


2015-01-26 09:30:28

Chuck Trese

Patrick,

Here's an array formula that works for any named range (assuming range is one column wide, of course). If you name your range MyRange, then the below array formula works:

=INDIRECT("R"&MAX(ROW(MyRange)*(MyRange<>""))&"C"&COLUMN(MyRange),FALSE)

Enter using Ctrl-Shift-Enter.


2015-01-26 09:07:53

Chuck Trese

btw,
Here is an improvement on the formula given in the tip (finding last item in all of column B):

=INDIRECT("B"&MAX(ROW(B:B)*(B:B<>"")))

Again, this is an array formula, so you must enter it by pressing Control-Shift-Enter.


2015-01-26 08:56:28

Chuck Trese

The given (corrected) formula:
=INDIRECT("B"&MAX(ROW(1:1048576)*(B1:B1048576<>"")))
only works as an array formula. This means you do not enter it by pressing Enter, you have to press Control-Shift-Enter (sometimes called CSE). When you do this correctly, Excel will put curly braces around the formula and it will give correct results.

Patrick, your formula is correct, but same problem. Enter using Control-Shift-Enter, all at the same time.


2014-11-21 13:06:44

Patrick

Hi Allen or anyone that can help:

I used the following formula to find the last value in column G between rows 170 to 190 with some blank cells...

=INDIRECT("G"&MAX(ROW(170:190)*(G170:G190<>"")))

and I get the #VALUE! error message.

Thank you,

Patrick


2014-11-17 15:35:46

Hank

This suggestion for included blank column
=INDIRECT("B"&MAX(ROW(1:1048576)*(B1:1048576<>"")))
does not function for Excel 2010.
Would appreciate correction.


2014-10-04 11:49:02

Pete

Thanks, very much, I am saving lots of time here:

=AVERAGE(INDIRECT("k"&D1&":k"&D2))

to get the average even when new data is added.

However this seems not to work in Graph data ranges! If I try to keep my charts updated in the same way, I get a Formula error every time. Do chart ranges work differently?

Thanks,

Pete


2014-10-01 17:16:39

Don

@Pete

The ADDRESS function returns a text-string of the address. In order for it to be used to return the value at that address it needs to be put inside the INDIRECT() function.

=INDIRECT(ADDRESS(row_num,col_num)

It's a beautiful thing! No more hard-coded Column letters.

I take it one more step. I name my columns, use the COLUMN() function and the ROW() function.
=INDIRECT(ADDRESS(ROW(),COLUMN(<column name>))

While I'm all excited about this, that COLUMN() function with NAMES is handy in VLOOKUP()'s for bullet proofing the value (first argument) and offset (third argument). It makes for long formulas but if someone inserts a column or deletes one there is no problem.

Let's say you've Named the following
- Column where Argument 1 values are: PartNumberCol
- Table where you are looking up the information (Argument 2): PartsLocationTable
- Column in PartsLocationTable where the information is that you need: PartsBinCol

Argument 1: INDIRECT(ADDRESS(ROW(),COLUMN(PartNumberCol))
Argument 2: PartsLocationTable
Argument 3: COLUMN(PartsBinCol) - COLUMN(PartsLocationTable) + 1


2014-09-29 16:36:50

Pete

Please no vba, just functions/formula.

I have data that I update daily by adding new rows. I want to use the new row number in other calculations

eg =COUNTIFS(L6:L56,"Won",J6:J56,">0")

If I add 3 rows of data L59 and J59 will become the new addresses in the formula above.

I tried it using

=COUNTA(A:A)+5 (in cell D2)

to get the number of used rows (adding a constant, known offset) and then use this in

=ADDRESS(D2,12)( in cell F2)

.. but this

=COUNTIFS(L6:F2,"Won",J6:J56,">0")

does not work, nor does

=COUNTIFS(L6:ADDRESS(D2,12),"Won",J6:J56,">0")

How can I get a formula to use the address reference I found with the ADDRESS function?

Thanks,

Pete


2014-07-30 06:50:27

Haley

The second formula in this article is incorrect. "B1:1048576" is not a valid range. It's missing the column indicator after the colon.

Even when fixed this formula is returning the first value in column B, not the last, and results in a #REF! error when the first cell in the range is blank.


2013-12-31 06:18:06

Michael (Micky) Avidan

@Courage,
Try to learn all about the 'OFFSET' function.
In order to help you - please upload your workbook to one of many File Hosting sites and present the link to the file.
Please explain - in details - the requested results as per your file.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2013-12-30 18:31:58

Courage

I need to make a list on a tab that is separate from my Data. I want the list to return column C info when Column H is empty.
But, I would like to look up the bottom 5 to 10 entries, so the first 5-10 empty cells in column H?

Could you help with this? Or is it possible with a formula?


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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.