UDF for Last Cell in Range

harrycosh

New Member
Joined
Feb 27, 2009
Messages
25
Help!

I need a UDF which encorporates the xlUp or alternative that finds the last cell in a range. The range contains formula's and the methods that I have been using give me the result of the last cell with a formula in it rather than the last cell with text or a value in it. I have used formula's that have blanks ("") in them, which is the main thing that is confusing the issue

Thanks in advance
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
This will give you the cell reference for the last row

Code:
Function LASTCELL(Cell As Range) As Variant
    Dim Finalrow As Long
    Finalrow = Cells(Rows.Count, Cell.Column).End(xlUp).Row
    
    LASTCELL = Cells(Finalrow, Cell.Column).Address

End Function

I hope that this helps
 
Upvote 0
Thanks for the response de909

When I have used the function it displays the cell address of the last cell with a formula in it, which in my case is blank. Is it possible to get the address of the last cell with a text displayed in the range, rather than the last cell in the range with a formula in it?

Thanks again in advance
 
Upvote 0
Perhaps this (although note that if your blanks are actually spaces " " - which is all too common, then this will fail again):

Code:
Function GetLastRow(rng As Range) As Long
On Error Resume Next
GetLastRow = rng.Find(What:="?*",After:=rng.Cells(1,1),LookIn:=xlValues,SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row
End Function
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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
Back
Top