Excel- any formula to return last number in a column

Ebraham

Board Regular
Joined
Mar 21, 2015
Messages
215
Hi.


In sheet one. In cell b20. I want to return last number of column d of sheet2.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

etaf

Well-known Member
Joined
Oct 24, 2012
Messages
5,656
Office Version
  1. 365
Platform
  1. MacOS
Try
=LOOKUP(2,1/(sheet2!D:D<>""),sheet2!D:D)
 

XOR LX

Well-known Member
Joined
Jul 2, 2012
Messages
4,517
Try
=LOOKUP(2,1/(sheet2!D:D<>""),sheet2!D:D)

Although that will work, it will have to process more than a million cells. Whether the last number happens to be in row 3 or row 1048576 is indifferent; it will still be forced to check every single cell in the column.

=INDEX(Sheet2!D:D,MATCH(9.9E+307,Sheet2!D:D))

is much less resource-heavy.

Regards
 
Last edited:

etaf

Well-known Member
Joined
Oct 24, 2012
Messages
5,656
Office Version
  1. 365
Platform
  1. MacOS
thanks for that tip - noted the formula
but not working in my test sheet
 

XOR LX

Well-known Member
Joined
Jul 2, 2012
Messages
4,517

ADVERTISEMENT

thanks for that tip - noted the formula
but not working in my test sheet

Are you referring to the previous formula I had there? Apologies - I amended my post.

Regards
 

etaf

Well-known Member
Joined
Oct 24, 2012
Messages
5,656
Office Version
  1. 365
Platform
  1. MacOS
no
=INDEX(Sheet2!D:D,MATCH(9.9E+307,Sheet2!D:D))

 

XOR LX

Well-known Member
Joined
Jul 2, 2012
Messages
4,517

ADVERTISEMENT

I assume we're talking about numbers here, since that's what the OP asked for? And not e.g. numbers formatted as text?

Can you post a small dataset for which that formula does not return the last number in the column?

Regards
 

etaf

Well-known Member
Joined
Oct 24, 2012
Messages
5,656
Office Version
  1. 365
Platform
  1. MacOS
my bad - missed the numbers - so works fine
 

XOR LX

Well-known Member
Joined
Jul 2, 2012
Messages
4,517
No worries.

Actually, even if the column contains mixed datatypes and the OP wished to return the last non-blank entry, it would still be far better to use e.g.:

=INDEX(Sheet2!D:D,AGGREGATE(14,6,MATCH(CHOOSE({1,2},REPT("z",255),9.9E+307),Sheet2!D:D),1))

than your LOOKUP construction. Despite the length of the above, it will still process far, far more quickly.

Of course, if there are null strings ("") within the column which need to be ignored then this will not be sufficient.

Regards
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,881
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Actually, even if the column contains mixed datatypes and the OP wished to return the last non-blank entry, it would still be far better to use e.g.:

=INDEX(Sheet2!D:D,AGGREGATE(14,6,MATCH(CHOOSE({1,2},REPT("z",255),9.9E+307),Sheet2!D:D),1))

than your LOOKUP construction.
Provided, of course, that the user is working in XL2010, or later, as that is when the AGGREGATE function was introduced.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,954
Messages
5,834,570
Members
430,297
Latest member
xa_gta

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top